Service Builder Template

In this article, you’ll learn how to create a Liferay portlet application that uses Service Builder as Liferay modules. To create a Liferay Service Builder project via the command line using Blade CLI or Maven, use one of the commands with the following parameters:

blade create -t service-builder -v 7.0 [-p packageName] projectName

or

mvn archetype:generate \
    -DarchetypeGroupId=com.liferay \
    -DarchetypeArtifactId=com.liferay.project.templates.service.builder \
    -DartifactId=[projectName] \
    -Dpackage=[packageName] \
    -DapiPath=[apiPath] \
    -DliferayVersion=7.0

You can also insert the -b maven parameter in the Blade command to generate a Maven project using Blade CLI.

The template for this kind of project is service-builder. Suppose you want to create a Service Builder project called tasks with a package name of com.liferay.docs.tasks. You could run the following command to accomplish this:

blade create -t service-builder -v 7.0 -p com.liferay.docs.tasks tasks

or

mvn archetype:generate \
    -DarchetypeGroupId=com.liferay \
    -DarchetypeArtifactId=com.liferay.project.templates.service.builder \
    -DgroupId=com.liferay \
    -DartifactId=tasks \
    -Dpackage=com.liferay.docs.tasks \
    -Dversion=1.0 \
    -DapiPath=com.liferay.api.path \
    -DliferayVersion=7.0

This task creates the tasks-api and tasks-service folders. In many cases, a Service Builder project also requires a -web folder to hold, for example, portlet classes. This should be created manually. After running the command above, your project’s directory structure looks like this:

  • tasks
    • gradle (only in Blade CLI generated projects)
      • wrapper
        • gradle-wrapper.jar
        • gradle-wrapper.properties
    • tasks-api
      • bnd.bnd
      • build.gradle
    • tasks-service
      • bnd.bnd
      • build.gradle
      • service.xml
    • build.gradle
    • [gradlew|pom.xml]
    • settings.gradle

To generate your service and API classes for the *-api and *-service modules, replace the service.xml file in the *-service module. Depending on your build tool, you can build your services by executing

blade gw buildService

or

mvn service-builder:build

from the tasks root directory. Note that blade gw only works if the Gradle wrapper can be detected. To ensure the availability of the Gradle wrapper, be sure to work in a Liferay Workspace.

The mvn service-builder:build command only works if you’re using the com.liferay.portal.tools.service.builder plugin version 1.0.145+. Maven projects using an earlier version of the Service Builder plugin should update their POM accordingly.

The generated module is functional and is deployable to a Liferay DXP instance. To build upon the generated app, modify the project by adding logic and additional files to the folders outlined above.

Running Service Builder and Understanding the Generated Code

Using Service Builder in a Maven Project

Service Builder with Maven

« Service TemplateService Wrapper Template »
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています