Reputation: 2247
In a .war file I've deployed to Tomcat, I'm getting a NoClassDefFoundError on a library that was there during build.
My .war is being created with an Ant build script. In the script is what I believe is a custom target (automatically created by the office New Project tool) which gets my dependencies from a .pom from my .m2 repository, and puts them in my WEB-INF/lib folder. One of those libraries is one that I helped program, and built on my machine with Maven. For historical reasons, this new project needs to use Ant, which is why I'm doing it this way.
The .war builds fine. All classes are found. I deploy it to tomcat, and when I run the only servlet command, which does very little at the moment but call a few classes in the .jar I built earlier, I get this:
exception
javax.servlet.ServletException: Servlet.init() for servlet InitLDAP threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:619)
root cause
java.lang.NoClassDefFoundError: Could not initialize class com.myjarlibrary.ConnectionAgent
com.mywarservice.MyServlet.init(MyServlet.java:45)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:619)
I have no idea why.
I'm building both the .jar and the .war with Java 6. Tomcat version 6.0.29. The MyServlet.java:45
is the first time the .jar library is called, but there's another library called first (just log4j). Checking the webapps
folder, I see the library is sitting where it should be. Someone else's very similar .war (same dependencies, similarly code-sparse) runs just fine on the same Tomcat, but I've been unable to find the relevant difference, unless it's that it was built with Maven instead of Ant, like the library was.
What could be going wrong?
Upvotes: 0
Views: 767
Reputation: 128859
java.lang.NoClassDefFoundError: Could not initialize class com.myjarlibrary.ConnectionAgent
That doesn't indicate that the class itself isn't found. It says in its own confusing way that there's an error initializing the class. You should look at the com.myjarlibrary.ConnectionAgent
and see if there's any problem with its superclasses or any static fields or static initializers. Most likely a class or interface referenced by one of those is missing. You might find more detail by looking into the logs, too. Check catalina.out and the localhost.* log for additional errors, not to mention whatever logs your application may write to.
Upvotes: 3