Skip to main content
23 Aug 2012

Now a days, Maven becoming more popular tool in the category of project building tools. If you have ever worked with enterprise projects using maven you already know how important a local maven repository and proxy is.

And we also know that we often require usage of Liferay Service Builder in our day to day Portal development activities.

So by referring this post you can get better idea about how to use Liferay Service Builder with Maven SDK.

Here, I assume that you are already aware about the Liferay Maven SDK as well as how to create a new Liferay portlet using Maven.

Lets assume you already have a maven based liferay portlet.  

  1. Open the pom.xml file of your portlet, and add the following property under the <properties> tag. If the <properties> tag does not exist in your pom.xml then you can add it manually as a last tag under the main <project> tag of the pom.xml.

                                                                                                                                                           <service.api.dir>src/main/java-service-api</service.api.dir>                                                                                                                                              
    Here, you can define your own folder/directory path which will contains the source code of your service API.
     

  2. Add following plugin under the <plugins> tag of your pom.xml. The following plugin is required for adding more source directories to the pom.xml. So using this plugin we can add folder/directory mentioned in <service.api.dir> as a java source directory and tells maven to compile that also.

                                                                                                                                                        <plugin>

                  <groupId>org.codehaus.mojo</groupId>

                  <artifactId>build-helper-maven-plugin</artifactId>

                  <version>1.3</version>

                  <executions>

                            <execution>

                                       <id>add-source</id>

                                       <phase>generate-sources</phase>

                                       <goals>

                                                <goal>add-source</goal>

                                        </goals>

                                       <configuration>

                                                <sources>

                                                          <source>${service.api.dir}</source>

                                                 </sources>

                                       </configuration>

                            </execution>

                     </executions>

           </plugin>                                                                                                                                                                                                      

  3.  Add one more following plugin under the <plugins> tag of your pom.xml. The following plugin handles the copying of project resources to the output directory.

          <plugin>

                   <groupId>org.apache.maven.plugins</groupId>

                    <artifactId>maven-resources-plugin</artifactId>

                     <version>2.3</version>

           </plugin>

  4. Add following resources just after the <plugins> tag of your pom.xml. So the above resource plugin can find the required project resources to copy into output directory.                                                                                                                                           
            <resources>
                    <resource>
                            <directory>src/main/java</directory>
                            <includes>
                                <include>service.properties</include>
                            </includes>
                    </resource>
                    <resource>
                            <directory>src/main/resources</directory>
                    </resource>
            </resources>
     
  5. Now your portlet is ready to deal with the stuff of building liferay service with maven sdk. Enter following command to build service. Here, I assume that the valid service.xml file is already exist under WEB-INF directory of your portlet.
       
        mvn clean liferay:build-service

  6. Congratulations!!! You are done.