Blogs

Blogs

Getting started with Liferay Maven SDK

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.
Thanks Mika! I will give it a try!
Nice! Thanks Mika!
Thanks!
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.java:550)
at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:369)
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)
at 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)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.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 ..
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.
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
Mika,
Will there be any updates for EE artifacts ? Since this will pull the artifacts from sonatype repository which will have only CE versions
Its nice.......Thank u
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
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
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?
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.
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.
[...] 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
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?
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
Thanks !! I'll try it.
[...] 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
This http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/creating-liferay-plugins-with-maven link is much more clear.
Is there an undeploy goal available for liferay maven plugin, if not is there a recommended way of undeploying plugins using maven?
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.
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?
I didnt understand your doubt. Could you ellobrate more?
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.