November 20, 2012

Liferay classloader issue when overriding a Liferay service class under tomcat

I had to override the ThemeDisplay class, located in the service area of Liferay.

To do so, I created an ext plugin and put my overridden implementation of the class into the right package.

On my local server, everything goes smooth, as well as on several other servers.

On another server though, I hit a NoSuchMethodException on the one method I added to the new class, as if the overridden class wasn't loaded. And indeed it wasn't picked up by the classloader

As someone very wise said on this thread
"The problem is related to a class loading issue with the app server / servlet container. The order of loading files usually depends on the jvm, filesystem, OS and the weather."
So depending on your configuration, it looks like your ext service jar will be picked up before the real service jar... or not.

The easiest way to fix the problem

The overriden class of the service jar get bundled in a TOMCAT_HOME/lib/ext/ext-myPlugin-service.jar

So put yourself in the TOMCAT_HOME/lib directory, which jar files are loaded before liferay lib/ext directory, and create a symbolic link from this directory to the ext service jar :
$ cd [TOMCAT_HOME]/lib
$ ln -s ext/ext-myPlugin-service.jar

And voila, your service ext jar is loaded first and you can use your overridden class.

That solution came from Alex Weirig here

Hope this help.

No comments:

Post a Comment