Page 1 of 1

Mysterious ClassNotFound Exception

PostPosted: Wed Aug 08, 2012 9:49 pm
by sandra
In my current project i'm getting the following error while trying to execute the code:

Code: Select all
Aug 08, 2012 12:45:18 PM org.apache.catalina.core.StandardWrapperValve invoke
Schwerwiegend: Servlet.service() for servlet [RTFServlet] in context with path [/sv] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.docx4j.openpackaging.packages.OpcPackage
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
   at de.fhzw.portal.sv.util.print.ModulhandbuchDocxUtil.generateModulhandbuch(ModulhandbuchDocxUtil.java:108) <---
   at de.fhzw.portal.sv.print.RTFServlet.service(RTFServlet.java:99)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


In the line marked with "<--" I'm doing this:
Code: Select all
WordDocument doc = new WordDocument(array); //creates a docx


I exactly to the same think in a test project and there were no problems so far.
I included the same docx4j jar Files in both projects. What could cause this error?

fyi: I'm using Tomcat 7 and Java 7

Best regards
Sandra

Re: Mysterious ClassNotFound Exception

PostPosted: Thu Aug 09, 2012 9:13 am
by jason
I've never had that problem with tomcat, provided of course that docx4j is in WEB-INF/lib

Re: Mysterious ClassNotFound Exception

PostPosted: Fri Aug 10, 2012 8:40 pm
by sandra
What should be in the WEB-INF/lib the jar Files?

Re: Mysterious ClassNotFound Exception

PostPosted: Fri Aug 10, 2012 8:56 pm
by sandra
I copied the files to my tomcat/lib directory and already added them to my build path, is there more I have to do?

Re: Mysterious ClassNotFound Exception

PostPosted: Sat Aug 11, 2012 8:51 am
by jason
For a webapp, generally the jars should be in that webapp's WEB-INF/lib dir (not tomcat/lib, and not on the path you use to start tomcat).

Put docx4j and all its dependencies in your webapp's WEB-INF/lib dir.

Generally you'll want your build process (eg maven or ant) to create a war file which does this for you.

All this is general tomcat knowledge, not in any way specific to docx4j

Re: Mysterious ClassNotFound Exception

PostPosted: Sun Aug 12, 2012 2:56 am
by sandra
I found the problem. I don't know why, but there was one jar missing in my tomcat directory.

jason wrote:For a webapp, generally the jars should be in that webapp's WEB-INF/lib dir (not tomcat/lib, and not on the path you use to start tomcat).


You don't need to do that if you put them in the tomcat/lib directory. Especially if you use the jar's for more than one project...

Anyway, thanks for your help very much!