Liferay Pro 3.5.0, Tomcat 5.5, and Spring Portlet Sample
July 27, 2005 – 18:38 | java, springI finally got around to try hot-deploying a standard JSR 168 portlet into Liferay Pro 3.5+Tomcat 5.5.9. The portlet application being used is the Spring Portlet Support Sample Application. The bottom line: it does the job, and in a satisfactory manner, meanwhile, it also leaves me some wishlist items.
There is some Liferay documentation discussing how to hot deploy portlets. Unfortunately it's mostly geared towards an Enterprise installation, whereas I'm working with the Professional. I end up with a heavily modified version of the deployer ant script provided in the document:
-
<project name="portlet-deployer" basedir="." default="deploy">
-
<target name="init">
-
<property environment="env"/>
-
<!-- Tomcat -->
-
<property name="app.server.type" value="tomcat" />
-
<property name="app.server.dir" value="E:\tomcats\5.5.9-liferay" />
-
<property name="app.server.deploy.dir" value="${app.server.dir}/webapps" />
-
<property name="liferay.dir" value="${app.server.dir}/liferay"/>
-
<path id="project.classpath">
-
<pathelement location="${env.ANT_HOME}/lib/ant.jar" />
-
<fileset dir="${app.server.dir}/shared/lib" />
-
<pathelement location="${app.server.dir}/common/lib/servlet-api.jar" />
-
</path>
-
</target>
-
<target name="deploy" depends="init">
-
<java classname="com.liferay.portal.tools.PortletDeployer" classpathref="project.classpath" fork="true" newenvironment="true">
-
<!-- Required Arguments -->
-
<jvmarg value="-Ddeployer.base.dir=./"/>
-
<jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}"/>
-
<jvmarg value="-Ddeployer.app.server.type=${app.server.type}"/>
-
<jvmarg value="-Ddeployer.portlet.taglib.dtd=${liferay.dir}/WEB-INF/tld/liferay-portlet.tld"/>
-
<!-- Optional Arguments -->
-
<jvmarg value="-Ddeployer.jboss.prefix=1"/>
-
<jvmarg value="-Ddeployer.tomcat.lib.dir=${app.server.dir}/shared/lib"/>
-
<!-- Dependent Libraries -->
-
<arg value="${app.server.dir}/shared/lib/util-taglib.jar"/>
-
<arg value="${app.server.dir}/shared/lib/util-java.jar"/>
-
<!--
-
<arg value="${app.server.deploy.dir}/ext.ear/lib/util-jsf.jar" />
-
-->
-
</java>
-
</target>
-
</project>
Once that and the Spring Portlet sample war are both ready in the 'my_portlets' directory, next thing you want to do is to copy everything under liferay/WEB-INF/lib into Tomcat's shared/lib. That's for Liferay to be able to load the portlet applications.
Now just run "ant deploy" to do the actual deployment. If Tomcat is running, and this is not the first time the same application is deployed, the deployer will spit out a bunch of warnings about "unable to delete" files. They can actually be safely ignored. The updated version of those files are actually in deployment by now if you go to check the timestamps. And Tomcat will pick up the changes and reload the application in the next scanner run. So, there, hot-redeploy works, too.
Once deployed, the JSR 168 portlets are treated no differently from Liferay's built-in ones. You can add them right away from the dropdown list at the bottom of the page. The Spring portlet sample consists of four simple portlets which all seem to live happily. I just used the generic sample application without any container flavors. The only change I made was to copy the liferay/WEB-INF/tld/liferay-portlet.tld to the sample app's WEB-INF/tags directory, and rename it to 'portlet.tld'. However later on I took a look into the deployed application and found out that the Liferay deployer actually did something similar automatically while it processed the war file, so I suspect even that bit of modification wasn't necessary.
I also noticed another trick the deployer played with the war file - if there is a jar file in the war file that's already in shared/lib (e.g. log4j.jar), the deployer would automatically drop it from the application being deployed. Assuming I didn't misunderstand this behavior, I seriously think it should at least be made optional by the deployer, because it could cause things anywhere from inconsistent to downright bad. For example, Spring distributes in two ways - one way is a monolithic spring.jar, the other a set of spring-*.jar files grouping classes into different functionalities. Liferay has a spring.jar, whereas the Spring sample application chooses to use a subset of spring-*.jar. You get some inconsistencies right there if they are running different versions of Spring. And what appeared to be "downright bad" to me is, since the web app specific log4j.jar is dropped, all the log4j configuration happening within the web app is now applied globally, and whichever portlet application that gets loaded the last takes over the control of the entire server's logging operation... Edit: I have since found out that if you point the property deployer.tomcat.lib.dir to somewhere else (say an empty directory), the jars wouldn't get filtered.
The last item on my wish list for the next Liferay release would be some more elegant way to hot-deploy portlets that doesn't involve any Ant script or command line execution. E.g., a directory scanner? or an Administrative portlet that lets me upload war files?

18 Responses to “Liferay Pro 3.5.0, Tomcat 5.5, and Spring Portlet Sample”
Hi Jing Xue,
I am trying to deploy the sample to liferay prof 3.5 tomcat 5.028 following what you said ;
1)Copy the liferay/WEB-INF/tld/liferay-portlet.tld to the sample app’s WEB-INF/tags directory, and rename it to ‘portlet.tld’
2) Copy everything under liferay/WEB-INF/lib into Tomcat’s shared/lib
3) have the build.xml and spring_sample_portlet.war in the folder my_portlets
4)run ant deploy
I havent setup the tables in the database (what do I need to do to create the tables to work with HBN)
I got bunch of exception because of this;
Caused by: java.sql.SQLException: Table not found: COMPANY in statement......
By Emmanuel on Aug 3, 2005
You do need to create the tables first. You can find the sql scripts at http://prdownloads.sourceforge.net/lportal/liferay-portal-ent-3.5.0-sql.zip. Pick the property script for the database you are using.
By Jing Xue on Aug 3, 2005
Thanks for the tip, I will download the sql scripts and run it for MySQL DB.
By Emmanuel on Aug 5, 2005
Thanks, I was able to add the Spring examples to Liferay with your steps. and the sql scripts.
I was checking out the portlets and I got an error in the Mode Name View portlet when I use the control maximize from the portal (when I am in the view mode) I get;
General Error
org.springframework.web.portlet.mvc.PortletModeNameViewController does not handle action requests
was curious if you got that too.
By Emmanuel on Aug 8, 2005
I got this error with some of my own controller. It's because one of the base spring portlet controllers throws this exception as default implementations of handleSubmitAction and handleSubmitRender. You need to override both in your controller.
By Jing Xue on Aug 8, 2005
Hi,
I got the portlet deployed smoothly. However, the porlet does not show any content when I added it in to Liferay tab. What I could see is just a bordered empty box.
Could you tell me what the problem is ?
By Mike Tran on Aug 25, 2005
Hmm, I have never seen anything like that before. Is it a JSR168 portlet? Was there anything in the log? I would try to ask on Liferay's development forums.
By Jing Xue on Aug 27, 2005
Hi,
I just tried the sample portlet from the spring support page. and deployed it into the liferay 3.6.1-tomcat.
The portlet got deployed smoothly also, but i'm having the same problem as Mike Tran, I'm getting just a bordered empty box too!
By Jose Choi on Aug 31, 2005
Did you guys check out the Spring Portlet Wiki at http://opensource2.atlassian.com/confluence/spring/display/JSR168/Home? Somebody else was able to deploy it to Liferay Pro 3.6.0-tomcat. I'll also give it a try as soon as I have some time.
By Jing Xue on Aug 31, 2005
Hi,
Thanks a lot for your info Jing Xue. I've checked the Wiki before trying it and noticed someone who was able to do it. Anyway not many details were given.
FYI, I did the "easy" installation of Liferay Pro, i.e. just download liferay-portal-pro-3.6.1-tomcat.zip and extract it. Then I unzipped the spring sample portlet, of course I had to manually make some changes to the sample portlet, mainly:
a) delete log4j.jar and commons-logging.jar from the WEB-INF/lib in the sample portlet
b) copy the liferay-portlet.tld from liferay into the sample portlet tags directory and rename it to portlet.tld
c) add the lines
com.liferay.portal.servlet.PortletContextListener
to the sample portlets web.xml, otherwise the portlet won't be listed in liferay.
Finally, I copied the whole portlet directory into the webapps folder in tomcat.
the portlet seems to deploy successfully, just that there isn't any content, just a empty box!
Do you think I should try the "expert" installation and deploy by using the ant scripts provided by liferay instead?
Thanks a lot for your help Jing Xue!
By Jose Choi on Aug 31, 2005
Jose, I would try using the hot deploy script. See the post I just made http://www.digizenstudio.com/blog/2005/08/31/liferay361-tomcat-spring/
Good luck!
By Jing Xue on Aug 31, 2005
Hi,
I have the Spring portlets fully working with Liferay. However, I now want to put them into a category of portlets in Liferay. e.g. Wiki
Have you ever tried such things ?
PS I once followed the instruction at http://opensource2.atlassian.com/confluence/spring/display/JSR168/Home but yet it does not work at all.
By Mike Tran on Dec 1, 2005
Thanks for your help,
now, i can run the "ant deploy" but the remain problem is there is nothing happen! There is nothing in \webapps but i an deploy is successful!
Can you help me!
Thanks,
By TaiTH on Jun 13, 2006
Thankx for your tips.
I followed your tips and now I can deploy easier. I use Liferay 4.1.1. & Tomcat 5.0
By Quan on Aug 23, 2006
Hi,
actually i am deploying the spring samples("Books portlet") on Liferay 4.1.1. The portlets appear in the list of portlets. I am also able to add the portlet "books" to the main page but i am getting the following error in the portlet content: The requested resource (/spring-samples/WEB-INF/servlet/view) is not available
Can anyone help me on this issue?
Thanks,
Kenz K.
By kenz on Sep 1, 2006
i have been able to solve the problem which was in the view controller need to to add the jsp..
By kenz on Sep 5, 2006