« Back

Getting started with Liferay Maven SDK

Company Blogs February 1, 2012 By Mika Koivisto Staff

This will be the first in series of posts on how to develop Liferay plugins with Maven. In this post we'll start by creating a new parent project for your plugins and add a portlet project to it. You need to have your maven environment setup with maven and java installed. If you don't know how to do it I would recommend reading Maven: The Complete Reference from Sonatype, Inc. The chapter 2 has good instructions on how to install maven.
 
1) Download and install Liferay 6.1.0 bundle. In these posts we assume it's tomcat bundle but you can use any bundle. I'll refer to the bundle install location is LIFERAY_HOME from now on. If you need instructions on how to install bundle please refer to Liferay 6.1 User Guide.
 
2) Create a new directory which will be your project root. This is the location where you would extract Liferay plugins SDK if you were using Ant. Then in that directory create a pom.xml file.
 
Now you should adjust groupId and artifactId to match you project. Also set the value of liferay.auto.deploy.dir to LIFERAY_HOME/deploy. This is where the plugin is copied for Liferay to deploy. The liferay.version property is set to version of Liferay you are using. 
 
3) Open command prompt or terminal and go to your project directory. Next we'll going to create a portlet project using a liferay portlet project template. Run
 
mvn archetype:generate
 
That command will create a list of available project templates like below:
 
 
Choose number 24 or what ever the number you have for com.liferay.maven.archetypes:liferay-portlet-archetype
 
Next you will be asked to choose the template version: 
 
 
Choose number 6 or what ever you have for 6.1.0 version.
 
Next you will be asked to provide groupId, artifactId and version:
 
 
For groupId use the same as in the first pom.xml. In my case it would be com.liferay.sample. For artifactId I chose sample-portlet as this is the directory it will create. Version should be the same as the project parent. Once you have confirmed the values maven will create the portlet project and add it to you parent project as module automatically.
 
Now you project structure should be something like this:
 
 
4) Go to sample-portlet directory and run 
 
mvn package
 
This will compile any classes and packages the portlet war file in target directory. 
 
5) To deploy the portlet into your Liferay bundle you can run
 
mvn liferay:deploy
 
Now you have created your first Liferay plugin project with maven and deployed it to your Liferay bundle.
Threaded Replies Author Date
Thanks Mika! I will give it a try! Jens Meinecke February 1, 2012 11:23 PM
Nice! Thanks Mika! Jonas Yuan February 2, 2012 8:54 AM
Thanks! Bijan Vakili February 2, 2012 2:06 PM
Perfect! Igor Beslic February 3, 2012 12:31 AM
Hi Mika, I tried the above steps and created a... Saswat Sahoo February 6, 2012 4:44 AM
Saswat, I don't see any Liferay classes in your... Mika Koivisto February 6, 2012 10:21 AM
Ya right. I am directly calling view.jsp page.... Saswat Sahoo February 7, 2012 5:24 AM
Mika, Will there be any updates for EE... Kamesh Sampath February 8, 2012 8:32 PM
Its nice.......Thank u Pulla Reddy February 9, 2012 4:32 AM
i like it... allcott almond February 17, 2012 10:11 PM
Mika, I was trying to develop a Mojo with... Kamesh Sampath February 18, 2012 9:21 AM
Saswat, bundling WAR as jar will not include... Kamesh Sampath February 18, 2012 9:25 AM
If mvn package is used to package a portlet,... vijay k March 5, 2012 11:02 PM
I guess all of the dependencies have to be... vijay k March 5, 2012 11:13 PM
Hello Mika, is there an integration between... Denis Signoretto March 13, 2012 3:48 AM
[...] Some time ago I posted on how you can get... Anonymous March 15, 2012 5:55 PM
Hi, I am looking for documentation about the... David García González March 21, 2012 3:57 AM
Hi, I have 3 questions: I am using eclipse... Witold Wolski May 24, 2012 7:52 AM
Thanks !! I'll try it. Ashish Renapurkar July 11, 2012 5:29 AM
[...] When you say "old Icefaces applications"... Anonymous August 23, 2012 12:42 PM
[...] Have you seen this:... Anonymous March 12, 2013 1:53 AM
[...] Stay tuned to this blog for more updates... Anonymous March 15, 2013 2:28 AM
This... Joga Krish April 8, 2013 2:53 AM
Is there an undeploy goal available for liferay... Advait Trivedi June 3, 2013 7:15 PM
it depends on the bundle you use, if you are... Kamesh Sampath June 3, 2013 8:47 PM
I am using liferay tomcat bundle, but this... Advait Trivedi June 3, 2013 9:11 PM
I didnt understand your doubt. Could you... Joga Krish June 4, 2013 2:59 AM
I need maven goal to undeploy liferay plugins... Advait Trivedi June 4, 2013 7:32 AM

Thanks Mika! I will give it a try!
Posted on 2/1/12 11:23 PM.
Nice! Thanks Mika!
Posted on 2/2/12 8:54 AM.
Posted on 2/2/12 2:06 PM.
Posted on 2/3/12 12:31 AM in reply to Bijan Vakili.
Hi Mika,
I tried the above steps and created a sample project. I m running it in jetty server by adding necessary dependencies. While viewing the view.jsp its giving the following error.

HTTP ERROR 500

Problem accessing /. Reason:

Could not initialize class com.liferay.taglib.portlet.DefineObjectsTei
Caused by:

java.lang.NoClassDefFoundError: Could not initialize class com.liferay.taglib.portlet.DefineObjectsTei
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.j­ava:550)
at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:3­69)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:252­)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:498)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:578)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1642)
at org.apache.jasper.compiler.Parser.parse(Parser.java:181)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
a­t org.apache.jasper.compiler.ParserController.parse(ParserController.java:140)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:435)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:608)
­at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:360)
­at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at­ org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225­)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937­)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)­
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)­
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at­ org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:284)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:115)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at­ org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225­)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937­)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)­
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)­
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at­ org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
­at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
a­t org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnec­tion.java:1048)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java­:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:­40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
­at java.lang.Thread.run(Unknown Source)

Please help me out ..
Posted on 2/6/12 4:44 AM.
Saswat, I don't see any Liferay classes in your stacktrace other than the missing one. Are you requesting the jsp directly perhaps. The exception suggest to me that you are missing util-taglib.jar from your portlet. Did it go through Liferay deployer?

Please post questions like this to the message boards instead.
Posted on 2/6/12 10:21 AM in reply to Saswat Sahoo.
Ya right. I am directly calling view.jsp page. But I see the util-taglb.jar in WEB-INF\lib folder.
As I m doing the packaging in jar (not war) So I am not going for deploy step.
I created one standalone java class which will run the jetty server locally and mapped the view.jsp in <welcome file list>
While calling the view.jsp in localhost its giving error as:
Failed to load or instantiate TagExtraInfo class: org.apache.pluto.tags.DefineObjectsTag286$TEI

my view.jsp is as follows:

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>Sample JSP Portlet</b>. Use this as a quick way to include JSPs.

Is there anything need to be changed in taglib uri
Posted on 2/7/12 5:24 AM in reply to Mika Koivisto.
Mika,
Will there be any updates for EE artifacts ? Since this will pull the artifacts from sonatype repository which will have only CE versions
Posted on 2/8/12 8:32 PM in reply to Saswat Sahoo.
Its nice.......Thank u
Posted on 2/9/12 4:32 AM.
Mika,

I was trying to develop a Mojo with Liferay Plugins and running in to issues with Maven version that plugins default to which is "2.0.10" and am using 3.0.x, is there any plans to upgrade the maven.version of the plugin to most compatible version with that of 3.x something like 2.1.x ? The problem is typically with the execution of the mojo test case were its loading a inappropriate Plexus container

I have opened a thread here http://www.liferay.com/community/forums/-/message_boards/message/12573766
Posted on 2/18/12 9:21 AM in reply to allcott almond.
Saswat,
bundling WAR as jar will not include your src/main/webapp folder, as the default maven lifecycle for jars will include only src/main/java and src/main/resources that the reason you are getting class not found error, my question to yo u why you want to deploy it as jar ? why war cant be used in jetty ???? it will be great if you can open the topic in forum where we can discuss further
Posted on 2/18/12 9:25 AM in reply to Kamesh Sampath.
If mvn package is used to package a portlet, does liferay-plugin-package.properties (especially portal-dependency-jars property) come into play? I guess not. Every jar that the portlet uses (compile/runtime) should be defined as a standard maven <dependency> in the pom.xml.

is that accurate statement?
Posted on 3/5/12 11:02 PM.
I guess all of the dependencies have to be included as maven <dependency> in pom.xml (which kind of makes sense and thats maven standard anyway). Otherwise Liferay has to provide custom plugins, to "package" and configure for eclipse (eclipse:eclipse plugin) or any other plugin using dependencies (dependency:tree etc), that kind of bring/use the liferay-plugin-package.properties.
Posted on 3/5/12 11:13 PM in reply to vijay k.
Hello Mika,

is there an integration between Liferay IDE and Maven? Can I generate the Eclipse project from maven and manage the packaging and deploying from LiferayIDE with Maven?

Thanks,
Denis.
Posted on 3/13/12 3:48 AM.
[...] Some time ago I posted on how you can get started creating portlets with Liferay Maven SDK now I’m going to show how you can add themes to your project. If you need a refresher on how to get started... [...] Read More
Posted on 3/15/12 5:55 PM.
Hi, I am looking for documentation about the goals of Liferay Maven SDK.

Something like this:

http://maven.apache.org/plugins/maven-war-plugin/index.html

Is there any documentationg about the Liferay Maven sdk?
Posted on 3/21/12 3:57 AM in reply to .
Hi,
I have 3 questions:
I am using eclipse liferay
1) How do I import the project into eclipse? Should I import it as an maven project or as an existing Liferay portlet project (which does not works for me)?

2) I am developing JSF portlets. I was using in "eclipse-liferay" new -> liferay jsf portlet. Is there an equivalent for maven?

Witold
Posted on 5/24/12 7:52 AM in reply to David García González.
Thanks !! I'll try it.
Posted on 7/11/12 5:29 AM.
[...] When you say "old Icefaces applications" are you referring to ICEfaces 1.8? If so, then I would recommend that you perform a small test to see if it will work with ICEfaces 3.1. The latest version of... [...] Read More
Posted on 8/23/12 12:42 PM.
[...] Have you seen this: http://www.liferay.com/web/mika.koivisto/blog/-/blogs/12322618 Sign in to vote. Flag Please sign in to flag this as inappropriate. Mark as an Answer [...] Read More
Posted on 3/12/13 1:53 AM.
[...] Stay tuned to this blog for more updates related to Liferay IDE, namely Remote IDE connector update and also some news about upcoming 2.0-Milestone-1 version of Liferay IDE that will have Liferay... [...] Read More
Posted on 3/15/13 2:28 AM.
This http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/creatin­g-liferay-plugins-with-maven link is much more clear.
Posted on 4/8/13 2:53 AM in reply to .
Is there an undeploy goal available for liferay maven plugin, if not is there a recommended way of undeploying plugins using maven?
Posted on 6/3/13 7:15 PM.
it depends on the bundle you use, if you are using Liferay tomcat bundle you could well use the Maven Tomcat plugin http://tomcat.apache.org/maven-plugin.html and use the undeploy tasks from them.
Posted on 6/3/13 8:47 PM.
I am using liferay tomcat bundle, but this maven tomcat plugin needs manager web app deployed, which doesnt come with Liferay Tomcat bundle, and I dont want to add this app for this. Considering this, is there any option for me?
Posted on 6/3/13 9:11 PM in reply to Kamesh Sampath.
I didnt understand your doubt. Could you ellobrate more?
Posted on 6/4/13 2:59 AM in reply to Advait Trivedi.
I need maven goal to undeploy liferay plugins from local liferay tomcat bundle. Now, liferay has deploy goal but no undeploy goal. Kamesh proposed using maven tomcat plugin, but that needs Tomcat's "manager" webapp to be deployed, which is not available with Liferay Tomcat bundle, and I do not want to deploy it.

So, given this, what options do I have to achieve undeploy using maven goal? I hope this is clear.
Posted on 6/4/13 7:32 AM in reply to Joga Krish.