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

2 comments:

Unknown said...

Exactly what I was looking for... thank you for the reference!

Anonymous said...

Really helpful!