I've been trying to get Jasper reports to work now for weeks. It works fine in Eclipse, the demo from the Jasper website works. It just won't work from my jsp page in JBoss.
My jsp page is pretty basic. It calls a method in a class. It definitely gets to that point because I have output diagnostics. When I call any Jasper method it bombs out with this error:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
I've dumped jar files everywhere. I've even gone as far as dumping this set of jars in my jre/lib/ext
folder.
- batik-1.5
- commons-beanutils-1.8.0
- commons-collections-3.2.1
- commons-digester-1.7
- commons-javaflow-20060411
- commons-logging-1.1.1
- iText-2.1.7
- jasperreports-4.6.0
- jasperreports-applet-4.6.0
- jasperreports-fonts-4.6.0
- jasperreports-javaflow-4.6.0
- log4j
- org.eclipse.jdt.core_3.7.1.v_B76_R37x
- poi-3.6
But nothing makes any difference.
Thanks for your replies and suggestions. I resorted to dumping jars in the jre/lib/ext folder because I had tried it with them in JBoss default/lib and it wouldn't work. However, I have now removed all references apart from the Jboss default/lib, but it still doesn't work.
When I first start JBoss and run my jsp page I get this stacktrace:
2012-06-19 08:03:49,349 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Kanban].[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.<clinit>(JRXmlDigesterFactory.java:179)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at my.test.TestClass.compileReport(TestClass.java:73)
at my.test.TestClass.show(TestClass.java:35)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
That seems to suggest the error is with org/apache/commons/logging/LogFactory but I definitely have commons-logging-1.1.1.jar in JBoss default/lib.
If I then run the jsp page a second time I get a different error:
2012-06-19 08:04:23,080 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/Kanban].[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
at my.test.TestClass.compileReport(TestClass.java:73)
at my.test.TestClass.show(TestClass.java:35)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
I can provide any additional information that might help someone diagnose my problem. Does anyone know what I'm doing wrong here?
You're confusing
ClassNotFoundException
withNoClassDefFoundError
. Your classpath was already fine. Please do not pollute the JRE library. You should absolutely undo that. Just placing the JARs in/WEB-INF/lib
was been sufficient. Don't forget to undo any changes made in Eclipse project's "Build Path" settings as well.This particular
NoClassDefFoundError
basically means that one of thestatic
variables or blocks of the mentioned class threw an exception during initialization which in turn caused that the classloader couldn't load the class. The real root cause of that exception should be visible further down in the stacktrace. Since you didn't post the entire stacktrace, it isn't possible to explain you why exactly it failed to initialize and how to solve it.So, read the bottommost root cause in the stacktrace, interpret the exception/message and fix it accordingly.
Well first thing is to stop throwing jar files all over the place. By doing this you are complicating the problem, and any future classpath problems you may have. Please note I am not trying to be condescending, it sounded that way when I read it before posting. It is just a pet peeve of mine having ran into people doing this and then months or years later troubleshooting something else and they complicate everything.
So step 1 is figure out what jar file
net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
is in. If it is the same as JasperReports 4.5 then it will be in youjasperreports-4.6.0
.Step 2 is to find the proper place to put the jar file. According to some JBoss docs I found here it should be located in you JBoss install directory at
server/default/lib
. The description for that folder is:Step 3 is to restart JBoss and makes sure it works.
It should be working now, or you may get a different error if you are missing other needed libraries. If so repeat the steps again.
Finally step 4 is to take a little time and go clean up all those jars where ever you put them. I know the instinct is to simply leave it, or even throw extra jars in the appropriate place because you do not know if you need them or not. Trust me it will bite you one day. Best to keep everything clean and organized from the get go.