JasperCompileManager.compileReportToFile throws exception: java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream

0

I have a simple standalone java class that is trying to compile a jrxml file into a jasper file. This class worked with JasperReports library version 3.6 but not that I've upgraded to 5.5 it is throwing the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletOutputStream
        at net.sf.jasperreports.web.util.WebResourceHandlersExtensionRegistory.<clinit>(WebResourceHandlersExtensionRegistryFactory.java:47)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealRClassLoader.java:157)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForNamessLoader.java:115)
        at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(Clls.java:53)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instaRegistry(DefaultExtensionsRegistry.java:237)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRies(DefaultExtensionsRegistry.java:214)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRies(DefaultExtensionsRegistry.java:162)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRees(DefaultExtensionsRegistry.java:133)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExns(DefaultExtensionsRegistry.java:105)
        at net.sf.jasperreports.engine.DefaultJasperReportsContext.getExte(DefaultJasperReportsContext.java:246)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.fines(ComponentsEnvironment.java:119)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getBundles(ComponentsEnvironment.java:109)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.gets(ComponentsEnvironment.java:97)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getentBundles(ComponentsEnvironment.java:179)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.getSchations(JRReportSaxParserFactory.java:84)
        at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.configurePBaseSaxParserFactory.java:131)
        at net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParseSaxParserFactory.java:94)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParsmlDigesterFactory.java:1439)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigeRXmlDigesterFactory.java:1415)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.ja)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.ja)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.ja)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.ja)
        at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(CompileManager.java:137)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReportTJasperCompileManager.java:438)
        at com.recurrentsoft.ghv.JRC.main(JRC.java:21)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletOutputSt
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 28 more
 
Here is the relevant code that is being called:
JasperCompileManager.compileReportToFile(args[0], args[0].replaceAll("jrxml", "jasper"));  

Attachments: 
dana.peele's picture
Joined: Oct 29 2013 - 9:51am
Last seen: 5 years 12 months ago

4 Answers:

3

I solved my issue. I needed to included a jar with the javax.servlet library in my classpath. I don't know why but that fixed my problem. Hope this helps you.

Regards, Dana

dana.peele's picture
Joined: Oct 29 2013 - 9:51am
Last seen: 5 years 12 months ago

Dana,

Thanks for the follow up. It is odd that it needs a ServletOutputStream in what is supposed to be a Java SE library, but interesting to know that it works when provided with one. Personally, I think it is a bug in 5.5.0. Downgrading the library to 5.1.0 resolved the problem for me, and is probably also an option for you. This way I can keep using iReport instead of the new Eclipse based thing.

Best, Bailey

bsswartz - 6 years 2 weeks ago

Hi Dana,
which is the jar (name?) you included?
Thanks!

Nicolas

nsanitas - 6 years 2 weeks ago

We've needed to include the following jars in our build.xml:
<include name='joda-time-2.1.jar' />
<include name='servlet-api-2.4.jar' />

Now it compiles again.

gle3@invantive.com - 6 years 1 week ago
show 2 more...

Hello Dana,

My code is to compile jrxml file of report.
JasperCompileManager.compileReport(report1_jrxml.data)

I have upgraded from jasper 5.1 to 5.5, I got same error as you got.
NoClassDefFoundError: javax/servlet/ServletOutputStream

Then as per your suggestion I have included javax.servlet-5.1.12.jar in my classpath.
Now my report jrxml is "successfully compiled".
"But when my report contains HTML5 chart component". It gives me another exception : java.lang.NoClassDefFoundError: com/jaspersoft/jasperserver/api/engine/jasperreports/util/InstanceProductTypeResolver.

Following is complete stack trace :

java.lang.NoClassDefFoundError: com/jaspersoft/jasperserver/api/engine/jasperreports/util/InstanceProductTypeResolver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.jaspersoft.ji.license.LicenseManager.<clinit>(LicenseManager.java:99)
at com.jaspersoft.ji.license.JRLicenseProviderAdapter.requireLicense(JRLicenseProviderAdapter.java:75)
at com.jaspersoft.ji.license.JRLicenseProviderAdapter.requireFeature(JRLicenseProviderAdapter.java:70)
at com.jaspersoft.jasperreports.license.LicenseManager.requireFeature(LicenseManager.java:113)
at com.jaspersoft.jasperreports.highcharts.HighChartsUtils.requireHighchartsFeature(HighChartsUtils.java:49)
at com.jaspersoft.jasperreports.highcharts.charts.StandardChartComponent.<init>(StandardChartComponent.java:73)
at com.jaspersoft.jasperreports.highcharts.charts.ChartCompiler.toCompiledComponent(ChartCompiler.java:67)
at net.sf.jasperreports.engine.base.JRBaseComponentElement.<init>(JRBaseComponentElement.java:60)
at net.sf.jasperreports.engine.base.JRBaseObjectFactory.visitComponentElement(JRBaseObjectFactory.java:1693)
at net.sf.jasperreports.engine.design.JRDesignComponentElement.visit(JRDesignComponentElement.java:103)
at net.sf.jasperreports.engine.JRAbstractObjectFactory.getVisitResult(JRAbstractObjectFactory.java:89)
at net.sf.jasperreports.engine.base.JRBaseElementGroup.<init>(JRBaseElementGroup.java:84)
at net.sf.jasperreports.engine.base.JRBaseBand.<init>(JRBaseBand.java:80)
at net.sf.jasperreports.engine.base.JRBaseObjectFactory.getBand(JRBaseObjectFactory.java:527)
at net.sf.jasperreports.engine.base.JRBaseReport.<init>(JRBaseReport.java:230)
at net.sf.jasperreports.engine.base.JRBaseReport.<init>(JRBaseReport.java:151)
at net.sf.jasperreports.engine.JasperReport.<init>(JasperReport.java:83)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:225)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:241)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:174)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)
at com.savo.jasper.test.ValidateJrxml.compileJRxml(ValidateJrxml.java:45)
at com.savo.jasper.unittestcases.cannedReports.UsageTrendByUserGroup_TestCase.testCompileJrxml(UsageTrendByUserGroup_TestCase.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.jaspersoft.jasperserver.api.engine.jasperreports.util.InstanceProductTypeResolver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 59 more

Please suggest. Thanks in advance.

Regards,
Jayashree

jayashreep - 6 years 1 day ago

Jayashree:

I don't see any class resembling that name in the Jasper Reports API.

D

dana.peele - 6 years 1 day ago
0

For whatever it is worth, I am getting the same error when my code tries to compile a report, after upgrading to version 5.5.  

bsswartz's picture
Joined: Nov 1 2013 - 2:56pm
Last seen: 6 years 2 weeks ago
0

Hello Dana,

Please refer to following URL:
http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/Jas...

I am using following method to compile the jrxml file.
Method: compile(java.lang.String sourceFileName) : compiles the XML report design file received as parameter, and returns the compiled report design object.

Before upgrading to japser 5.5, I was working on jasper 5.1 where compilation was successful given input as any of my reports XML files.

Now in jasper 5.5 this method works if I don't add any HTML5 chart component to the report, otherwise gives exception as java.lang.NoClassDefFoundError: com/jaspersoft/jasperserver/api/engine/jasperreports/util/InstanceProductTypeResolver.

Please suggest. I have already included javax.servlet-5.1.12.jar in classpath.


Thanks,
Jayashree.
 

jayashreep's picture
Joined: May 31 2012 - 5:49am
Last seen: 5 years 12 months ago
0

Hello Dana,

I have solved this exception, by including following jars.

  • jasperserver-api-engine-5.5.0.jar
  • jasperserver-api-engine-impl-5.5.0.jar
  • commons-lang-2.5.jar
  • jasperserver-api-common-impl-5.5.0.jar

Previously in jasper 5.1 this jars were not needed.

 

But Now I’m trying to solve another exception:

INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader- Loading XML bean definitions from URL [jar:file:/G:/Savo_Insight/jasperreports-server-5.5/apache-tomcat/webapps/jasperserver-pro/WEB-INF/lib/jasperreports-highcharts-5.5.0.jar!/com/jaspersoft/jasperreports/highcharts/component_beans.xml]

net.sf.jasperreports.engine.JRException: Error compiling report design.

       at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:242)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:241)

       at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:174)

       at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:459)

       at com.savo.jasper.test.ValidateJrxml.compileJRxml(ValidateJrxml.java:45)

       at com.savo.jasper.unittestcases.dashReports.Administrator_MobileAdoption_TestCase.testCompileJrxml(Administrator_MobileAdoption_TestCase.java:83)

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

       at java.lang.reflect.Method.invoke(Unknown Source)

       at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

       at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

       at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

       at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

       at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

       at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

       at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

       at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

       at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.NullPointerException

       at com.jaspersoft.ji.license.LicenseManager.getInstance(LicenseManager.java:102)

       at com.jaspersoft.ji.license.JRLicenseProviderAdapter.requireLicense(JRLicenseProviderAdapter.java:75)

       at com.jaspersoft.ji.license.JRLicenseProviderAdapter.requireFeature(JRLicenseProviderAdapter.java:70)

       at com.jaspersoft.jasperreports.license.LicenseManager.requireFeature(LicenseManager.java:113)

       at com.jaspersoft.jasperreports.highcharts.HighChartsUtils.requireHighchartsFeature(HighChartsUtils.java:49)

       at com.jaspersoft.jasperreports.highcharts.charts.StandardChartComponent.<init>(StandardChartComponent.java:73)

       at com.jaspersoft.jasperreports.highcharts.charts.ChartCompiler.toCompiledComponent(ChartCompiler.java:67)

       at net.sf.jasperreports.engine.base.JRBaseComponentElement.<init>(JRBaseComponentElement.java:60)

       at net.sf.jasperreports.engine.base.JRBaseObjectFactory.visitComponentElement(JRBaseObjectFactory.java:1693)

       at net.sf.jasperreports.engine.design.JRDesignComponentElement.visit(JRDesignComponentElement.java:103)

       at net.sf.jasperreports.engine.JRAbstractObjectFactory.getVisitResult(JRAbstractObjectFactory.java:89)

       at net.sf.jasperreports.engine.base.JRBaseElementGroup.<init>(JRBaseElementGroup.java:84)

       at net.sf.jasperreports.engine.base.JRBaseBand.<init>(JRBaseBand.java:80)

       at net.sf.jasperreports.engine.base.JRBaseObjectFactory.getBand(JRBaseObjectFactory.java:527)

       at net.sf.jasperreports.engine.base.JRBaseReport.<init>(JRBaseReport.java:230)

       at net.sf.jasperreports.engine.base.JRBaseReport.<init>(JRBaseReport.java:151)

       at net.sf.jasperreports.engine.JasperReport.<init>(JasperReport.java:83)

       at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:225)

       ... 29 more

 

Have anyone encountered such an exception in 5.5?

 

Thanks,

Jayashree.

jayashreep's picture
Joined: May 31 2012 - 5:49am
Last seen: 5 years 12 months ago
Feedback
randomness