Recent Bloggers

David H Nebinger

68 Publications
23 février 2018

Jonas Choi

3 Publications
23 février 2018

Jamie Sammons

11 Publications
19 février 2018

Iacopo Colonnelli

2 Publications
17 février 2018

Christian Klein

1 Publications
15 février 2018

Jose M. Navarro

8 Publications
14 février 2018

Maria Sanchez

18 Publications
13 février 2018

Sergio González

5 Publications
13 février 2018

Minhchau Dang

15 Publications
31 janvier 2018

Koen Olaerts

3 Publications
30 janvier 2018
« Retour

Liferay's Architecture: Service Builder

Company Blogs 3 janvier 2013 Par 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 * 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.

Réponses Auteur Données
keep it coming Jorge! I am just loving this... Bharanidharan Viswanathan 4 janvier 2013 06:26
Thanks for the tip on the freemarker templates! Everest Liu 14 janvier 2013 09:23
Another great one, keep it up! Two typos you... Falko Werner 21 janvier 2013 04:02
Thanks for providing valuable article.. Ashish Ranjan 21 janvier 2013 05:32
I think the third party tool you were referring... Donald Barnes 16 août 2013 11:05
Hi Jorge, about Service Builder, can you... Denis Signoretto 1 octobre 2013 05:59
Thanks Jorge for your kind words :) Service... Tariq Dweik 12 novembre 2013 16:15

keep it coming Jorge! I am just loving this series.
Publié le 04/01/13 06:26.
Everest Liu
Thanks for the tip on the freemarker templates!
Publié le 14/01/13 09:23.
Another great one, keep it up!

Two typos you might want to fix in paragraph three:
- Service Biulder
- develped
Publié le 21/01/13 04:02.
Thanks for providing valuable article..
Publié le 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.
Publié le 16/08/13 11:05.
Hi Jorge,

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

Best Regards, Thanks.
Publié le 01/10/13 05:59.
Thanks Jorge for your kind words emoticon

Service Builder migration to use Freemarker was done by me
Publié le 12/11/13 16:15.