Using Class Loader Proxy classes to share plugins services
Scenario: you have two plugins, each one in its war. One of them (from now on "CLP Portlet")has a service (let's call it "myObject") and its service layer (myObjectServiceUtil, myObjectLocalServiceUtil, etc) and the second portlet (from now on "CLP Consumer Portlet") needs to use those services. We are going to use Class Loader Proxy classes to achieve this: these classes serialize model entities across webapps so that they can be shared.
The steps to implement this are the following:
- After build-service in "CLP Portlet", it appears a CLP-portlet-service.jar file in WEB-INF/lib/
- Make the jar available for the other plugin. You can do this two ways:
- Copy the .jar file into the "CLP Consumer Portlet" WEB-INF/lib folder
- Copy CLP-portlet-service.jar into the global application server library folder. For Tomcat it would be tomcat_home/lib/ext
- Remove other copies from portlet/WEB-INF/lib (otherwise you will get strange exception like "ClassCastException Cannot cast MyObjectServiceUtil to MyObjectServiceUtil")
- In addition to all this, you MUST make sure that the copied service jar is NOT included in the original plugin.
- The last step is to call the remote service methods from "CLP Consumer Portlet".
This is as easy as a local call: com.liferay.clp.service.MyObjectServiceUtil.testMethod();
And that's all!
Note: some issues has been discovered using Tomcat 6.0 (see http://issues.liferay.com/browse/LPS-8353) but they have been fixed and are ready for the next release