Forums de discussion

How to use Rome or JDOM in a Portlet?

thumbnail
Cameron McBride, modifié il y a 13 années.

How to use Rome or JDOM in a Portlet?

Expert Publications: 269 Date d'inscription: 08/02/11 Publications récentes
I checked out the source for the RSS portlet that comes built into Liferay, it uses Rome and JDOM for RSS. I double confirmed this by looking in the lib directory and I see the rome and jdom jar files.

1. I create a new portlet in eclipse.
2. I make a class file and I try to reference XmlReader or SyndFeed (both from Rome).
3. Eclipse cannot find the supporting class files for them.
4. I right click my portlet project and link it to the rome and jdom jar. Maybe the PluginSDK can find all the Liferay APIs but not those.
5. I deploy and start the server.
6. I add the portlet and boom, big errors where it cannot find the supporting class files.

How can I use the Rome and Jdom that is already built into Liferay in a portlet?

If that is not possible, how can I include my own two jar files without having to change class paths on the server?

Thanks!
thumbnail
Hitoshi Ozawa, modifié il y a 13 années.

RE: How to use Rome or JDOM in a Portlet?

Liferay Legend Publications: 7942 Date d'inscription: 24/03/10 Publications récentes
Rome and JDOM are just jar files included in the lib folder in WEB-INF. They're not integrated into Liferay source code.
thumbnail
Cameron McBride, modifié il y a 13 années.

RE: How to use Rome or JDOM in a Portlet?

Expert Publications: 269 Date d'inscription: 08/02/11 Publications récentes
Right, but since Liferay must have them in its classpath (since it uses them) it seems like my portlet would also be able to use them.

I have tried adding the two jars to my project in eclipse which allows me to build and deploy it. Once I deploy it into a running Liferay instance the portlet cannot find those class files. How can the stock RSS portlet find them but my portlet cannot?

It makes me think there is some extra XML file in my portlet project where I need to reference those jar files in order for it to work.
thumbnail
Manish Kumar Gupta, modifié il y a 13 années.

RE: How to use Rome or JDOM in a Portlet?

Liferay Master Publications: 535 Date d'inscription: 16/05/08 Publications récentes
Liferay bundled jars will not be available to your plugin because of different classloaders.

If you want Liferay to inject any of the third party library into your portlet, you should declare this in liferay-plugin-package.properties file of your plugin using following property

portal-dependency-jars=\
XXX.jar,\
YYY.jar
thumbnail
Sandeep Nair, modifié il y a 13 années.

RE: How to use Rome or JDOM in a Portlet?

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Hi Cameron,

To make it simple assume Liferay as a web application which has its own jars, similary when you deploy your portlets, they too are separate web application. And each webapp will have access to all the jar that are there in their lib directory or global directory.

To use the jars that are already used in Liferay root web app as Manish rightly mentioned you can inject the jars at the runtime as the method he has suggested in liferay-plugin-package.properties which is recommended one or you can put them in your portlets Web-inf lib directory.

The former method is recommended because you dont have to maintain multiple versions of same jar.

The fact that it is not showing error when you specify the jars in eclipse is because you have attaching jars in eclipse will not show error at compile time but at runtime whne u deploy since there are no jars attached with project that is (portlet/WEB-INF/lib) it will give you error

Regards,
Sandeep
thumbnail
Cameron McBride, modifié il y a 13 années.

RE: How to use Rome or JDOM in a Portlet?

Expert Publications: 269 Date d'inscription: 08/02/11 Publications récentes
Referencing the jars in the liferay-plugin-package.properties worked perfectly. Thank you for breaking that down for me.