Reputation: 484
I have a Maven project which provides low level API and basic functionality for a communication interface. I have a few other Maven projects which all depend on this one project, and implement specific communications based on the low level API. As these are Maven projects, when I build the higher level project into a .war file, the low level project is automatically included in the lib folder as a .jar file, along with every other dependency.
I deployed this project to a Tomcat 7, which already hosts several other webapps each with their own dependencies. It almost immediately produced a ClassNotFoundException, one of the classes from the low level project is missing. There are two strange things here:
Is it possible that some dependency conflict is causing this? I'm not sure about how Tomcat's classpath is working, but as far as I know it includes the lib folder of the Tomcat and the lib folders of all the webapps, in some order. This low level project requires a number of dependencies like commons-io, httpclient, log4j, etc. All of these jars are present in the lib folder of my webapp, but some of these jars have a different version in the Tomcat's lib project (e.g. httpcore-4.3.2.jar is in my webapp, and httpcore-4.0.jar is in the Tomcat's lib folder). I couldn't find an explanation but some people are mentioning that this scenario could result in this situation. I never experienced this issue before, with such jar conflict I always encountered java.lang.VerifyError (or sometimes ClassNotFoundException, but in these cases the class was actually missing from one of the dependency jar files).
Is it possible that such jar conflict is causing that the class using those jars is not loaded at all? I would find this very weird.
Update:
Sorry I forgot stacktrace. Here is what I see in the browser when opening the application:
Mar 09, 2018 2:30:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [hu.tsm.ccm.aif.mobilegateway.routes.init] in context with path [/AIFMobileGateway] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: hu.tsm.ccm.vxmlgateway.vxml.AbstractVxmlWalker
at hu.tsm.ccm.aif.mobilegateway.responses.InitResponse.<init>(InitResponse.java:47)
at hu.tsm.ccm.aif.mobilegateway.routes.init.doGet(init.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
This hu.tsm.ccm.vxmlgateway.vxml.AbstractVxmlWalker class is present on the classpath in a jar file in the webapp's lib folder. Another class from this jar, namely hu.tsm.ccm.vxmlgateway.api.Version is being loaded successfully.
Upvotes: 2
Views: 1312
Reputation: 578
Exception java.lang.NoClassDefFoundError
means that some classes is missed in classpath that used as import (import
expression) in AbstractVxmlWalker
. The dependency for AbstractVxmlWalker
is not present in classpath.
Upvotes: 0
Reputation: 484
It seems issue was related to jar file scanning during Tomcat start. Tomcat start took 20 minutes, and I suspected this was due to jar scanning, so I added all jar files to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in catalina.properties file. After this Tomcat start was only 2 minutes, and suddenly, without any other changes, my application is working fine.
Upvotes: 1