Using Service Builder in a Maven Project

Liferay’s Service Builder is a model-driven service generation tool that is frequently used by many Liferay module projects. If you have a Liferay Maven project, you may be wondering if Service Builder works with your Maven modules; the answer is a resounding yes!

The easiest way to add Service Builder to your Maven project is to create a new Maven project using Liferay’s provided Service Builder archetype. You can learn how to generate a Service Builder Maven project by visiting the Service Builder Template tutorial. In some cases, this may not be possible due to a number of reasons:

  • You’re updating a legacy Maven project to follow OSGi modular architecture.
  • You have a pre-existing modular Maven project and don’t want to start over.

Time to get started!

  1. Apply the Service Builder plugin in your Maven project’s pom.xml file:


    Service Builder is applied by specifying its groupId, artifactId, and version. The configuration tag used above is an example of what a Service Builder project’s configuration could look like. All the configuration attributes above should be modified to fit your project.

    The above code configures Service Builder for a blade.servicebuilder.svc module. When running Service Builder with this configuration, the project’s API classes are generated in the blade.servicebuilder.api module’s src/main/java folder. You can also specify your hibernate module mappings, implementation directory name, model hints file, Spring configurations, SQL configurations, etc. You can reference all the configurable Service Builder properties in the Service Builder with Maven reference article. Also, visit the Defining an Object-Relational Map with Service Builder tutorial for more information on defining a service.xml file to configure Service Builder.

  2. Apply the WSDD Builder plugin declaration directly after the Service Builder plugin declaration:


    The WSDD Builder is necessary to generate your project’s remote services. Visit the Creating Remote Services tutorial for more information on WSDD (Web Service Deployment Descriptor). Similar to the Service Builder configuration, the service.xml file is set to define your project’s remote services. Also, the outputDirName defines where the *_deploy.wsdd and *_undeploy.wsdd files are generated. Make sure to define your server-config.wsdd file, as well.

Terrific! You’ve successfully configured your Maven project to use Service Builder by applying the and plugins in your project’s POM. To run Service Builder, see the Running Service Builder and Understanding the Generated Code tutorial for instructions.

« Deploying Liferay Maven Artifacts to a RepositoryCompiling Sass Files in a Maven Project »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0