REST Template

In this article, you’ll learn how to create a Liferay RESTful web service packaged in a Liferay module. To create a Liferay RESTful web service via the command line using Blade CLI or Maven, use one of the commands with the following parameters:

blade create -t rest -v 7.0 [-p packageName] [-c className] projectName


mvn archetype:generate \
    -DarchetypeGroupId=com.liferay \ \
    -DartifactId=[projectName] \
    -Dpackage=[packageName] \
    -DclassName=[className] \

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 rest. Suppose you want to create a RESTful web service project called my-rest-project with a package name of and a class name prefix of Rest. You could run one of the following commands to accomplish this:

blade create -t rest -v 7.0 -p -c Rest my-rest-project


mvn archetype:generate \
    -DarchetypeGroupId=com.liferay \ \
    -DgroupId=com.liferay \
    -DartifactId=my-rest-project \ \
    -Dversion=1.0 \
    -DclassName=Rest \
    -Dauthor=Joe Bloggs \

After running the command above, your project’s directory structure looks like this:

  • my-rest-project
    • gradle (only in Blade CLI generated projects)
      • wrapper
        • gradle-wrapper.jar
    • src
      • main
        • java
          • com/liferay/docs/application
        • resources
          • configuration
            • com.liferay.portal.remote.cxf.common.configuration.CXFEndpointPublisherConfiguration-cxf
    • bnd.bnd
    • build.gradle
    • [gradlew|pom.xml]

The generated module is a working RESTful web service 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.

« Portlet Toolbar Contributor TemplateService Template »