Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Share a jar between portlets
Hi,
I developed some struts-portlet in the plugin environment. My portlets need some java classes to work and they all need the same classes. For the moment, I put the source files of my classes in WEB-INF/src in each of my portlets. It's not really convenient and when I edit one of my class, I have to update the source files in all my portlet.
So, I want to create a jar with my classes and make it accessible to all my portlets. Is it possible ? How can I do that ?
I remember you that I develop plugin portlets.
Thanks for your help !
I developed some struts-portlet in the plugin environment. My portlets need some java classes to work and they all need the same classes. For the moment, I put the source files of my classes in WEB-INF/src in each of my portlets. It's not really convenient and when I edit one of my class, I have to update the source files in all my portlet.
So, I want to create a jar with my classes and make it accessible to all my portlets. Is it possible ? How can I do that ?
I remember you that I develop plugin portlets.
Thanks for your help !
Ganesh Ram:
This chain might help u.
It's not a jar from Liferay, It's a personnal jar with my own classes. If a add "portal.dependency.jars: MyPersonnalJar.jar" in liferay-plugin-package.properties. Where I put MyPersonnalJar.jar ?
Thanks for your help !
I am not much aware of portlet development using plugin environment, but can you bundle your all the portlets in a single war and deploy it?
Manish Kumar Gupta:
I am not much aware of portlet development using plugin environment, but can you bundle your all the portlets in a single war and deploy it?
I don't know. Right now, each portlet is in its own war.
Hi, I would also like to know if there is an easy way to achieve this.
Currently we are modifying the build scripts - for instance target compile on build-common-plugin.xml (fileset dir="......" includes=".....")
- Lari
Currently we are modifying the build scripts - for instance target compile on build-common-plugin.xml (fileset dir="......" includes=".....")
- Lari
If you put your jars in <liferay-plugins>\trunk\lib, then when u deploy the plugin portlet, the build takes care to put the jars in ur portlets web-inf/lib.
HTH,
Ganesh
HTH,
Ganesh
Here is another suggestion which I used for a demo.
I bundled my portlets into Liferay (all in the same war), by adding them to the web-content\html\portlet\MyPortlet1.
I think Liferay also has an extension folder (still in the same war) you can put them which is obviously better than putting them together with Liferay's portlets like I did.
HTH
Ora
I bundled my portlets into Liferay (all in the same war), by adding them to the web-content\html\portlet\MyPortlet1.
I think Liferay also has an extension folder (still in the same war) you can put them which is obviously better than putting them together with Liferay's portlets like I did.
HTH
Ora
Ganesh Ram:
If you put your jars in <liferay-plugins>\trunk\lib, then when u deploy the plugin portlet, the build takes care to put the jars in ur portlets web-inf/lib.
I don't have <liferay-plugins>\trunk\lib. I try to create it. But when I build my portlets, the jar is not put in web-inf/lib.
If we go through the build*.xmls in plugins folder we find that Liferay/plugin/lib folder will be used only while compiling the plugins directory or any of the included portlets/themes/web
These jars which are in plugins/lib are either already present in Liferay-Porta/WEB-INF/lib or they are used for executing ant targets etc.
So, if I understand correctly , the jars from plugins/lib will not be copied to the portlet/web-inf/lib.
Apart from the methods mentioned in this thread, another way can be to put your jar as part of Liferay-Portal/WEB-INF/lib and then in build.{username}.properties modify the required.portal.jars directory
I wont recommend this option though. The common jars that need to be put need to have a compelling reason to be in Liferay-Portal/WEB-INF/lib, if they are going to be used by a large number of portlets.
Hence, the option of bundling all portlets in a single war and putting the common jar in the WEB-INF/lib of that war, seems to be the way to go as of now.
These jars which are in plugins/lib are either already present in Liferay-Porta/WEB-INF/lib or they are used for executing ant targets etc.
So, if I understand correctly , the jars from plugins/lib will not be copied to the portlet/web-inf/lib.
Apart from the methods mentioned in this thread, another way can be to put your jar as part of Liferay-Portal/WEB-INF/lib and then in build.{username}.properties modify the required.portal.jars directory
I wont recommend this option though. The common jars that need to be put need to have a compelling reason to be in Liferay-Portal/WEB-INF/lib, if they are going to be used by a large number of portlets.
Hence, the option of bundling all portlets in a single war and putting the common jar in the WEB-INF/lib of that war, seems to be the way to go as of now.
Vihang Pathak:
Hence, the option of bundling all portlets in a single war and putting the common jar in the WEB-INF/lib of that war, seems to be the way to go as of now.
And how do you package all portlets in a single war ? Because all my portlets are in their own folder: <plug_in>/portlets/portlet_one-portlet, <plug_in>/portlets/portlet_two-portlet,...
And when you have the war file, you put the jars manually ?
Thanks or your help !
There are three ways to do that:
All three ways will require one master-portlet.xml which will contain references to all portlets that are in the single war.
1. Move all your portlets which are currently under plugins directory under the master-portlet. And run the build script
2. Keep the portlets where they are and in the master-portlet build.xml, build the other two portlets and copy the jars into the WEB-INF/lib of the master-portlet.war, thereby maintaining the package structure.
3. Make the jars manually(not the war) of the classes in other portlets, and package them in the master war.
All three ways will require one master-portlet.xml which will contain references to all portlets that are in the single war.
1. Move all your portlets which are currently under plugins directory under the master-portlet. And run the build script
2. Keep the portlets where they are and in the master-portlet build.xml, build the other two portlets and copy the jars into the WEB-INF/lib of the master-portlet.war, thereby maintaining the package structure.
3. Make the jars manually(not the war) of the classes in other portlets, and package them in the master war.
This is one important question.
One way is to create every portlet under one master portlet directory and deploy it as single .war file.
I wonder if idea of deploying these common jar files through Ext plugin is reasonable. It contains ext-lib\global directory and when I put some jar file in it it's copied to lib/ext during deployment.
That way the classes are available for every portlet.
One way is to create every portlet under one master portlet directory and deploy it as single .war file.
I wonder if idea of deploying these common jar files through Ext plugin is reasonable. It contains ext-lib\global directory and when I put some jar file in it it's copied to lib/ext during deployment.
That way the classes are available for every portlet.
Hi Jean, follow this steps,
1. create jar of your common source file and copy to the root context.
2. create context.xml in docroot/META-INF/context.xml
3. add this content in context.xml
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>
This will access your jar globally in the server.
1. create jar of your common source file and copy to the root context.
2. create context.xml in docroot/META-INF/context.xml
3. add this content in context.xml
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>
This will access your jar globally in the server.
Mohamed Ali:
Hi Jean, follow this steps,
1. create jar of your common source file and copy to the root context.
2. create context.xml in docroot/META-INF/context.xml
3. add this content in context.xml
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>
This will access your jar globally in the server.
It works. But this solution is not really convenient. If I want to share my portlets with other people, it's easier to give them just war files. With this solution, I must give: the portlet + a jar and explain them where to put all these files.
Thanks for your help