RE: Reusing third party library from LR core in my module

Jan Tošovský, modified 6 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
Dear All,

I need PdfBox library to process PDF files in my module. It is already the integral part of the LR portal in \tomcat-9.0.10\webapps\ROOT\WEB-INF\lib\pdfbox.jar

Can I somehow reuse it in my OSGi module?

Currently I embed it using this method https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/adding-third-party-libraries-to-a-module

But in this case that jar file is twice in the portal.

Jan
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Best solution: Just include it in your module.
If you really, really want to use the global version, I think you can add it to the list in the portal-ext property "module.framework.system.packages.extra" to make pdfbox available globally. But it isn't advisable to do so.

https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-0/resolving-classnotfoundexception-and-noclassdeffounderror-in-osgi-bundles
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
In addition, PDFBox is actually a module too, per https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox/2.0.14

This means that you can drop PDFBox in the Liferay deploy folder and it will be available as a regular OSGi service.

You can then just @Reference their published components or create classes from their exported packages, easy peasy.

Use "compile", not "compileInclude" or "compileOnly" in your build.gradle file and you should be golden.
​​​​​​​