Letzte Blogger

David H Nebinger

68 Nachrichten
23. Februar 2018

Jonas Choi

3 Nachrichten
23. Februar 2018

Jamie Sammons

11 Nachrichten
19. Februar 2018

Iacopo Colonnelli

2 Nachrichten
17. Februar 2018

Christian Klein

1 Nachrichten
15. Februar 2018

Jose M. Navarro

8 Nachrichten
14. Februar 2018

Maria Sanchez

18 Nachrichten
13. Februar 2018

Sergio González

5 Nachrichten
13. Februar 2018

Minhchau Dang

15 Nachrichten
31. Januar 2018

Koen Olaerts

3 Nachrichten
30. Januar 2018
« Zurück

Liferay's Architecture: Service Builder

Company Blogs 3. Januar 2013 Von Jorge Ferrer Staff

One of Liferay's "secret" ingredients, specially with regards to its architecture, is Service Builder. This is the tool that glues together all of Liferay's layers and that hides the complexities of using Spring or Hibernate under the hood.

Service Builder was originally built when Liferay used EJBs for everything (in fact it's name back then was EJBBuilder). EJBs were actually built around several very sound architectural patterns, but unfortunately the implementation was not as good. One significant pain for developers using EJBs was that it was necessary to write many XML files and Java classes to do even the simplest thing. So Brian Chan, Liferay's founder, who is known for being super efficient, decided to build a tool to do it for him. When Hibernate came around Brian was able to use Service Builder to switch from Entity EJB's to Hibernate literally over a weekend (I was blown away back then). Later on Service Builder also allowed switching from Service EJBs to Spring, gaining a lot of flexibility.

Service Builder has grown a lot since then. I used to be very skeptic with source code generation until I got to know Service Biulder better. It doesn't pretend to be a generic code generation tool, but rather to meet the needs of Liferay's developers (including plugin developers). It is also very opinionated, in the sense that it doesn't offer many options, just the ones we think fit better in Liferay's context. Because of that it might not be a tool for everybody but in exchange it provides a great degree of consistency to anything develped with it and is easier to learn. The general idea is simple, it just takes an XML file as an input (usually called service.xml) and generates the necessary persistance, service layer, web services, ... infrastructure around it. Check Liferay's Developer's Guide for info on how to use it.

One key breakthrough in the evolution of Service Builder actually happened with a contribution (can't remember the name of the contributor, does anyone know?). Previously, all of the code that was going to be generated was included as Strings within Java code and a community member took the time to move all of it to Freemarker templates. That has made the evolution and maintainence of Service Builder so much better that I don't have words to thank him :)

Right now, for every file that Service Builder will generate there is a Freemarker (.ftl) file associated with it. For example, do you want to find out how a *ServiceImpl.java file is generated, you just have to look at service_impl.ftl within com/liferay/portal/tools/servicebuilder/dependencies 

That's it for now, hope you liked the entry and see you soon for the next one.

Antworten im Thread Autor Datum
keep it coming Jorge! I am just loving this... Bharanidharan Viswanathan 4. Januar 2013 06:26
Thanks for the tip on the freemarker templates! Everest Liu 14. Januar 2013 09:23
Another great one, keep it up! Two typos you... Falko Werner 21. Januar 2013 04:02
Thanks for providing valuable article.. Ashish Ranjan 21. Januar 2013 05:32
I think the third party tool you were referring... Donald Barnes 16. August 2013 11:05
Hi Jorge, about Service Builder, can you... Denis Signoretto 1. Oktober 2013 05:59
Thanks Jorge for your kind words :) Service... Tariq Dweik 12. November 2013 16:15

keep it coming Jorge! I am just loving this series.
Gepostet am 04.01.13 06:26.
Everest Liu
Thanks for the tip on the freemarker templates!
Gepostet am 14.01.13 09:23.
Another great one, keep it up!

Two typos you might want to fix in paragraph three:
- Service Biulder
- develped
Gepostet am 21.01.13 04:02.
Thanks for providing valuable article..
Gepostet am 21.01.13 05:32.
I think the third party tool you were referring to which made your life easier may have been "Spring Surf" (which was formerly "Alfresco Surf") before Alfresco contributed it to Spring Source.
Gepostet am 16.08.13 11:05.
Hi Jorge,

about Service Builder, can you clarify differences between fetch and and find generated methods?

Best Regards, Thanks.
Gepostet am 01.10.13 05:59.
Thanks Jorge for your kind words emoticon

Service Builder migration to use Freemarker was done by me

Gepostet am 12.11.13 16:15.