Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Share code between ext and plugin portlets Mathieu Hicauber November 9, 2012 6:40 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 7:14 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 9, 2012 7:24 AM
RE: Share code between ext and plugin portlets Mathieu Hicauber November 9, 2012 7:27 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 9, 2012 7:34 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 7:46 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 9, 2012 8:11 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 8:16 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 9, 2012 8:34 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 8:48 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 9, 2012 8:53 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 12, 2012 7:36 AM
RE: Share code between ext and plugin portlets David H Nebinger November 12, 2012 8:19 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 12, 2012 8:41 AM
RE: Share code between ext and plugin portlets David H Nebinger November 12, 2012 8:47 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 12, 2012 8:51 AM
RE: Share code between ext and plugin portlets David H Nebinger November 12, 2012 9:42 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 12, 2012 9:45 AM
RE: Share code between ext and plugin portlets David H Nebinger November 12, 2012 10:00 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 13, 2012 3:47 AM
RE: Share code between ext and plugin portlets Florencia Gadea November 15, 2012 4:30 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 7:39 AM
RE: Share code between ext and plugin portlets Mathieu Hicauber November 9, 2012 7:30 AM
RE: Share code between ext and plugin portlets David H Nebinger November 9, 2012 7:44 AM
RE: Share code between ext and plugin portlets Mathieu Hicauber November 12, 2012 12:44 AM
RE: Share code between ext and plugin portlets David H Nebinger November 12, 2012 7:11 AM
RE: Share code between ext and plugin portlets Mathieu Hicauber November 12, 2012 7:18 AM
Mathieu Hicauber
Share code between ext and plugin portlets
November 9, 2012 6:40 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

Hello all,


Is there a recommended way to share a Utility class between ext plugin and portlet plugin ?
I have a XXXHelper class, which I use both in an overrided implementation of ThemeDisplay sitting in ext plugin, and also in a portlet plugin.

I'd prefer not to have to duplicate the class...

Thank you,

Mathieu.
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 7:14 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

If it's wrapped into a jar, it is still usable by EXT.

In plugin projects, add the jar as a dependency and it will get pulled in at deployment time so you don't have duplicated code issues.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 9, 2012 7:24 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Hi David,

How do you add the portlet-service.jar as a dependency in an ext plugin?

Regards,

Flor.
Mathieu Hicauber
RE: Share code between ext and plugin portlets
November 9, 2012 7:30 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

edit : refering to David message (cross message posting ^^)

I've done that in the past, but I like to use maven for versioning third party jars like this one and I experienced problem :

Put jar-v0.1 in ext-lib folder,
Refer to it as a dependency in portlet plugin
OK.

Put jar-v0.2 in ext-lib folder, delet v0.1
==> when ext is deployed, v0.1 is still present in ROOT/WEB-INF/lib, and is being picked up by LR classs loader.



So I was think of putting a utility class (like PortalUtil or so) in the ext plugin so it can be viewed by any portlet... but I don't see how.

According to you, no other solution apart putting the class in a jar, and the jar in ext plugin ?
Mathieu Hicauber
RE: Share code between ext and plugin portlets
November 9, 2012 7:27 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

I think what David sais is :

- put a jar in ext-lib folder in ext plugin
- then you can add it as dependency in any portlet through liferay-plugin-package.properties (after a first deployement of the ext plugin, so the jar is copied to ROOT/WEB-INF/lib)

HTH


Mathieu.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 9, 2012 7:34 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

So may be my problem is different. Not sure if I should start a new thread or keep writing in this one.

I've tried to use a portlet plugin in an ext plugin, these is what I've tried:

Option 1:

I included the portlet-service.jar generated from the portlet in the ext-lib/portal of the ext plugin. When I compile the ext plugin, the classes from the portlet are not being seen by the ext plugin. So I can't even compile.

Option 2:

I included the portlet-service.jar generated from the portlet in the ext-lib/global of the ext plugin. It compiles perfectly. But when I deploy the ext plugin in the server (after deploying the portlet), I get exceptions like:

1java.lang.ClassCastException: com.rcs.service.service.persistence.MessageSourcePK cannot be cast to com.rcs.service.service.persistence.MessageSourcePK


So this looks like a class loader issue, like there are duplicated classes.

I've read that putting the portlet-service.jar in tomcat/lib/ext is not a good practice, so I won't do it.

Are there any other suggestions?

Thanks,

Flor.
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 7:39 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Florencia Gadea:
How do you add the portlet-service.jar as a dependency in an ext plugin?


Well, this is a special case. The service jar must either be promoted to the global lib directory (lib/ext in tomcat) or copied to the ext-lib of the EXT plugin and deployed. There is additional work that you must do in either case.

For the global lib route, you must deploy the service plugin, stop the app container, move the jar to global lib, then start the container.

For ext-lib, you should move the jar prior to deployment (involves building a special deployment artifact for the plugin that had the service jar), bundle and deploy the EXT and the service plugin will need to have the service jar listed as a dependency jar before deployment, ...

Although the global lib route requires a restart of the app container, it is often the easier route than trying to figure out how to get the pieces working in the EXT plugin...
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 7:44 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Mathieu Hicauber:
I've done that in the past, but I like to use maven for versioning third party jars like this one and I experienced problem...


Yeah, versioning doesn't work out to well. EXT plugins rarely undeploy cleanly (at least in my experience) so you do get left with both versions (old and new) sitting out there.

I typically don't do the versioning on the 3rd party jars, mostly because I don't want to have to clean this stuff up afterwards and deal with class versioning conflicts if I don't get to it in time.

According to you, no other solution apart putting the class in a jar, and the jar in ext plugin ?


The only other option for sharing code is to use the global lib directory...
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 7:46 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Florencia Gadea:
I included the portlet-service.jar generated from the portlet in the ext-lib/global of the ext plugin. It compiles perfectly. But when I deploy the ext plugin in the server (after deploying the portlet), I get exceptions like:

1java.lang.ClassCastException: com.rcs.service.service.persistence.MessageSourcePK cannot be cast to com.rcs.service.service.persistence.MessageSourcePK


So this looks like a class loader issue, like there are duplicated classes.


Yep, you're missing the step of removing the service jar from the deployed plugin that has the service. There should only be one service jar in this scenario, the one in the global lib directory. Any other copies anywhere in the webapps folder will cause you similar headaches.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 9, 2012 8:11 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Hi David,

Thank you a lot for your help.

In your opinion, what do you think is the best option in order to make it easier for a non-technical user to deploy this?

Regards,

Flor.
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 8:16 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Florencia Gadea:
In your opinion, what do you think is the best option in order to make it easier for a non-technical user to deploy this?


The easiest route is the global lib usage scenario. The caveat here is that you have the app container deployment to contend with (shutdown, service jar move, restart).
Florencia Gadea
RE: Share code between ext and plugin portlets
November 9, 2012 8:34 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Ok, here is what I did and it looks that it's working:

1) Deploy portlet plugin.
2) Stop liferay.
3) Move portlet-services.jar from portlet plugin WEB-INF/lib to tomcat/lib/ext.
4) Deploy ext plugin.
5) Restart liferay.

Is it ok?

Thanks,

Flor.
David H Nebinger
RE: Share code between ext and plugin portlets
November 9, 2012 8:48 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Florencia Gadea:
Ok, here is what I did and it looks that it's working:

1) Deploy portlet plugin.
2) Stop liferay.
3) Move portlet-services.jar from portlet plugin WEB-INF/lib to tomcat/lib/ext.
4) Deploy ext plugin.
5) Restart liferay.


Yep, that's it, although you may want to adjust the order. If the service jar is not in lib/ext, the IDE will complain about the code in the EXT plugin since the jar is not available yet. If you trust your development skills, though, it's okay to order in this way.

For redeployments, you have two paths:

a) If you needed to build services as part of the deployment (i.e. you added/modified an entity, you added a method to XxxLocalServiceImpl or changed a method signature to an existing method in XxxLocalServiceImpl), you must repeat the process you did above.

b) If you did not need to build services but had a deployment (i.e. you changed the logic within a method in XxxLocalServiceImpl but did not change a method signature), your deployment process is slightly smaller:

1. deploy portlet plugin.
2. stop liferay.
3. delete service jar from portlet plugin (move is not necessary because jar did not change).
4. start liferay.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 9, 2012 8:53 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Ok, thanks for sharing you time and knowledge!

Best regards,

Flor.
Mathieu Hicauber
RE: Share code between ext and plugin portlets
November 12, 2012 12:44 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

Hi,

I'm back ! (not network at home emoticon )

The only other option for sharing code is to use the global lib directory...


Can you explain this other solution ?

Also, I've herad of a "client" directory at the root of the plugin sdk (newly rebaptized "shared" it seems). I didn't find any specific documentation about this, but from what I understood it could be a kind of "shared functionnalities" plugin. Am I right ? Isn't this the kind of plugin Ii'm looking for ?

Thank you,

Mathieu.
David H Nebinger
RE: Share code between ext and plugin portlets
November 12, 2012 7:11 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Mathieu Hicauber:
The only other option for sharing code is to use the global lib directory...


Can you explain this other solution ?


Put the jar in the global lib directory (tomcat's lib/ext directory, for example). This path has issues as you will not be able to do updates when the application container is running, but makes the code globally available.

Also, I've herad of a "client" directory at the root of the plugin sdk (newly rebaptized "shared" it seems). I didn't find any specific documentation about this, but from what I understood it could be a kind of "shared functionnalities" plugin. Am I right ? Isn't this the kind of plugin Ii'm looking for ?


Well the client directory used to be for creating web service clients for your SB web service entities, but I don't know if it still has the same meaning...
Mathieu Hicauber
RE: Share code between ext and plugin portlets
November 12, 2012 7:18 AM
Answer

Mathieu Hicauber

Rank: Junior Member

Posts: 79

Join Date: December 22, 2010

Recent Posts

I guessed the "share functionnalities" info from there :
http://issues.liferay.com/browse/LPS-30551

Thank you for your advices, I'll go with the jar in the ext/lib dir so I can reference it from other plugin.

Thanks again,

Mathieu.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 12, 2012 7:36 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Hi David,

Me again. After I move the portlet-service.jar to tomcat/lib/ext I get this exception:

1
2...
3SEVERE: Servlet.service() for servlet resourceEditor Servlet threw exception
4java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
5    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
6    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
7    at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:97)
8...


In my plugin portlet I need to use some JSPs. Does it mess with the lib/ext solution?

Regards,

Flor.
David H Nebinger
RE: Share code between ext and plugin portlets
November 12, 2012 8:19 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Does it happen if you restart tomcat?
Florencia Gadea
RE: Share code between ext and plugin portlets
November 12, 2012 8:41 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

David H Nebinger:
Does it happen if you restart tomcat?


Yes.
David H Nebinger
RE: Share code between ext and plugin portlets
November 12, 2012 8:47 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Florencia Gadea:
1
2...
3SEVERE: Servlet.service() for servlet resourceEditor Servlet threw exception
4java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
5    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
6    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
7    at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:97)
8...



The JSP stuff comes from the jstl.jar, which it looks like your portlet might not have. Add jstl-api.jar as a dependent jar in liferay-plugin-package.properties.
Florencia Gadea
RE: Share code between ext and plugin portlets
November 12, 2012 8:51 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

David H Nebinger:

The JSP stuff comes from the jstl.jar, which it looks like your portlet might not have. Add jstl-api.jar as a dependent jar in liferay-plugin-package.properties.



It is already added there:

 1portal.dependency.jars=\       
 2    jstl-api.jar,\
 3    jstl-impl.jar,\
 4        util-java.jar,\
 5        slf4j-api.jar,\
 6        slf4j-log4j12.jar,\       
 7        commons-collections.jar,\
 8        commons-fileupload.jar,\
 9        commons-httpclient.jar,\
10        commons-io.jar
David H Nebinger
RE: Share code between ext and plugin portlets
November 12, 2012 9:42 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

Is there a 'caused by' exception that you didn't show?
Florencia Gadea
RE: Share code between ext and plugin portlets
November 12, 2012 9:45 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

David H Nebinger:
Is there a 'caused by' exception that you didn't show?


Yes:

1Caused by: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
David H Nebinger
RE: Share code between ext and plugin portlets
November 12, 2012 10:00 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11113

Join Date: September 1, 2006

Recent Posts

This is typically an artifact of another class loader problem...

Does your service code reference any other classes (something other than one of your entity classes or primitives)?
Florencia Gadea
RE: Share code between ext and plugin portlets
November 13, 2012 3:47 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Apart from my entity classes, these are all the classes that my code references:

 1
 2import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
 3import com.liferay.portal.kernel.deploy.hot.HotDeployException;
 4import com.liferay.portal.kernel.deploy.hot.HotDeployListener;
 5import com.liferay.portal.kernel.exception.SystemException;
 6import com.liferay.portal.kernel.language.LanguageUtil;
 7import com.liferay.portal.kernel.util.HttpUtil;
 8import com.liferay.portal.kernel.util.StringPool;
 9import com.liferay.portal.kernel.xml.Document;
10import com.liferay.portal.kernel.xml.DocumentException;
11import com.liferay.portal.kernel.xml.Element;
12import com.liferay.portal.kernel.xml.SAXReaderUtil;
13import com.liferay.portal.util.Portal;
14import com.liferay.portal.kernel.util.PortalClassInvoker;
15import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
16import com.liferay.portal.kernel.events.SimpleAction;
17import com.liferay.portal.kernel.exception.SystemException;
18import com.liferay.portal.kernel.language.LanguageUtil;
Florencia Gadea
RE: Share code between ext and plugin portlets
November 15, 2012 4:30 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Well, I fixed this error. I deleted the jstl-api.jar from the portal dependency jars and I added it in WEB-INF/lib.

Thanks everyone for the help.