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
RE: OSGi: using Third party .jar results in NoClassDefFoundError's
Hi! I developed an OSGi module (Liferay 7.0 EE, service archetype) which uses jasperreports jar (v6.12.2) to generate PDFs. After Deployment I get a lot of errors (e.g. java.lang.NoClassDefFoundError: org/apache/commons/collections4/map/ReferenceMap). What do I have to do so that:
a.) my osgi module jar contains the neccessary jar and its dependencies.
b.) no more errors appear in the logs.To get access to the jar, I added it as a dependency in the the POM.
pom.xml
bnd.bnd
Are there any clear instructions what to do in this specific scenario? I only found vague ones.
a.) my osgi module jar contains the neccessary jar and its dependencies.
b.) no more errors appear in the logs.To get access to the jar, I added it as a dependency in the the POM.
pom.xml
<dependency>
<groupid>net.sf.jasperreports</groupid>
<artifactid>jasperreports</artifactid>
<version>6.12.2</version>
<scope>compile</scope>
</dependency>
bnd.bnd
Bundle-Name: jasper
Bundle-SymbolicName: com.example.service.jasper
Bundle-Version: 1.0.0
Bundle-Activator: com.example.service.activator.JasperReportServiceActivator
Export-Package: com.example.service.jasper.api
Are there any clear instructions what to do in this specific scenario? I only found vague ones.
Since you are using compile scope, jasper is used to compile your module but is not including it or any transitive dependencies into the module. This is what is causing all of your no class def errors, unresolved references, etc.
When building your module, you need to either include the deps in the module (shadow them in or build an uber jar) or they have to be deployed and available in the OSGi container (potential issues here in dealing with conflicts).
Either way, without the dependencies your module will not start.
When building your module, you need to either include the deps in the module (shadow them in or build an uber jar) or they have to be deployed and available in the OSGi container (potential issues here in dealing with conflicts).
Either way, without the dependencies your module will not start.
Hi David. Thanks for your reply. I removed the compile-scope in the pom above and also modified the bnd file you see below. Now with this configuration the errors are gone. Do you know if there is a more user-friendly way doing this?
Bundle-Name: jasper
Bundle-SymbolicName: com.example.service.jasper
Bundle-Version: 1.0.0
Bundle-Activator: com.example.service.activator.JasperReportServiceActivator
Export-Package: com.example.service.jasper.api
Import-Package: \
!com.adobe.xmp.*,\
!com.google.zxing.*,\
!com.ibm.icu.*,\
!java.xml.soap.*,\
!jaxen.*,\
!mondrian.*,\
!net.sf.barcode4j.*,\
!net.sourceforge.barbecue.*,\
!net.tascalate.javaflow.*,\
!org.apache.ant.*,\
!org.codehaus.groovy.*,\
!groovy.lang,\
!groovyjarjarasm.*,\
!net.sf.jasperreports.annotations.properties,\
!net.sf.jasperreports.metadata.properties,\
!netscape.*,\
!org.apache.*,\
!org.bouncycastle.*,\
!org.castor.*,\
!org.eclipse.jdt.*,\
!org.exolab.*,\
!org.hibernate.*,\
!org.krysalis.*,\
!org.mozilla.*,\
!org.olap4j.*,\
!org.springframework.*,\
!org.w3c.*,\
!javax.inject.*,\
net.sf.jasperreports.*,\
*
Include-Resource: @jasperreports-6.10.0.jar,\
@castor-xml-1.4.1.jar,\
@commons-beanutils-1.9.3.jar,\
@commons-collections4-4.2.jar,\
@commons-digester-2.1.jar,\
@commons-logging-1.1.1.jar,\
@ecj-4.4.2.jar,\
@itext-2.1.7.js7.jar,\
@jcommon-1.0.23.jar,\
@jfreechart-1.0.19.jar,\
@jackson-annotations-2.9.9.jar,\
@jackson-core-2.9.9.jar,\
@jackson-databind-2.9.9.jar,\
Nope, that's pretty much it...
Unfortunately I get further errors. What is this?
2020-04-01 09:43:00.088 ERROR [Framework Event Dispatcher: Equinox Container: f0cdf455-5673-001a-1759-ca29c79c48cd][com_example_service_jasper:97] FrameworkEvent ERROR
java.io.IOException: Exception in opening zip file: /var/liferay/osgi/state/org.eclipse.osgi/92/1/bundleFile
at org.eclipse.osgi.framework.util.SecureAction.getZipFile(SecureAction.java:305)
at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.basicOpen(ZipBundleFile.java:85)
at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.getZipFile(ZipBundleFile.java:98)
at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.checkedOpen(ZipBundleFile.java:65)
at org.eclipse.osgi.storage.bundlefile.ZipBundleFile.getEntry(ZipBundleFile.java:232)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:562)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:540)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:527)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:324)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:330)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:407)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:349)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1081)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at net.sf.jasperreports.engine.util.JRLoader.<clinit>(JRLoader.java:81)
at com.example.service.jasper.impl.JasperReportServiceImpl.generatePDFReport(JasperReportServiceImpl.java:42)
at com.example.service.application.impl.ApplicationDocumentJob.handleSendToFavoritRequest(ApplicationDocumentJob.java:115)
at com.example.service.application.impl.ApplicationDocumentJob.process(ApplicationDocumentJob.java:200)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at com.example.service.application.impl.ApplicationDocumentJob.doReceive(ApplicationDocumentJob.java:191)
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:26)
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:66)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:74)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:52)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:756)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:667)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: /var/liferay/osgi/state/org.eclipse.osgi/92/1/bundleFile (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.zip.ZipFile.<init>(ZipFile.java:169)
at org.eclipse.osgi.framework.util.SecureAction.getZipFile(SecureAction.java:288)
... 42 more
Exception in thread "liferay/scheduler_dispatch-250" java.lang.ExceptionInInitializerError
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:86)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:116)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:79)
at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:251)
at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:156)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:758)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1074)
at com.example.service.jasper.impl.JasperReportServiceImpl.generatePDFReport(JasperReportServiceImpl.java:50)
at com.example.service.application.impl.ApplicationDocumentJob.handleSendToFavoritRequest(ApplicationDocumentJob.java:115)
at com.example.service.application.impl.ApplicationDocumentJob.process(ApplicationDocumentJob.java:200)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at com.example.service.application.impl.ApplicationDocumentJob.doReceive(ApplicationDocumentJob.java:191)
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:26)
at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:66)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:74)
at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:52)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:756)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:667)
at java.lang.Thread.run(Thread.java:748)
</init></init></clinit></init></init></init></clinit>
Shut down Liferay, purge the osgi/state directory, then try again...
Thank you David. Deleting the files in osgi/state, liferay/work, tomcat/work, tomcat/temp and a restart solved the problem.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™