Friday, May 1, 2009

Don’t Curse “PortletConfigImpl” or Your Luck

There would hardly be any guy who is working with lliferay struts portlet in SDK environment and hasn’t faced the following error:

ERROR [PortletHotDeployListener:596] java.lang.ClassCastException:
com.liferay.portlet.PortletConfigImpl cannot be cast to com.liferay.portlet.Port
letConfigImpl


Some people must have broken their heads for days without any resolution. Now if my head functioning well (after breaking it for several days), you can follow the following two advices:
1. Never add portal-impl.jar (or struts.jar) as dependency jar inside liferay-plugin-package.properties (under portlet WEB-INF) to fix compilation errors. The default build file generated in the SDK environment doesn’t add the portal-impl.jar in the class path. Hence compilation fails as struts related classes are not found. To fix this one should add the "${app.server.lib.portal.dir}" to the build classpath (similar to the one done in sample struts portlet) rather than adding relevant jar(s) as dependency jar. Adding to the dependency jar will create conflicts.
portal-dependency-jars=\
         commons-lang.jar,\
         jfreechart.jar,\
         struts.jar,\
        portal-impl.jar


2. Make sure you overwrite the class loader. To do this one needs to add the new class loader “com.liferay.support.tomcat.loader.PortalClassLoader” in the context.xml under doocroor/META-INF directory. One can take reference from the sample struts portlet provider in the liferay SVN trunk

Liferay: Build File part of Sample Struts Portlet Breaks the Service Builder

If you are using SDK environment to build your standalone struts portlet and also building your services in the same environment don’t make the mistake of blindly using the build file provided in the sample liferay strurts portlet (http://svn.liferay.com/repos/public/plugins/trunk/portlets/sample-struts-liferay-portlet). If you use the build file, you will be astonished to see that your service classes are not being picked at the compile time and the build fails. On the other hand if you use the default build file created by the liferay SDK environment the struts classes are not added to the classpath. The result is same - the build fails. So problems never leave you – which ever way you go problem will accompany you. 

If you are using build file from the sample struts portlet make sure you amend the build file to add “docroot/WEB-INF/lib” to the class path. Add following to “plugin-lib.classpath” in the build file: 

If you are using the default build file, modify the “compile” target to add "${app.server.lib.portal.dir}" to the build time class path. This will add the portal-impl.jar to the classpath while compiling.