I am unable to deploy the WAR of a Jersey REST service on a Tomcat7 installation.
Tomcat runs inside a Docker container that so far has worked flawlessly.
I copy the WAR in /var/lib/tomcat7/webapps
and the initialisation fails complaining about a missing Guava class:
2016-09-25T13:29:55.444368315Z org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/simple02]]
. . . . .
2016-09-25T13:29:55.444460727Z Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function
....
2016-09-25T13:29:55.444483641Z at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:132)
Problem is: both jersey-container-servlet.jar (which contains JerseyServletContainerInitializer) and jersey-guava-2.8.jar (which contains Function) are in the same lib
directory inside the WAR.
My hypothesis is that Tomcat is actually ignoring my lib
directory altogether and running the JerseyServletContainerInitializer
from some Jersey JAR of its own.
I don't feel like sticking a single Guava JAR in the definition of a generic Tomcat container and would prefer to operate from my web.xml
.
Is this possible? I have tried several attempts without success.
The structure of the WAR is the following:
/WEB-INF
/classes
/com, etc. etc.
/lib
/javax.ws.rs-api-2.0.jar
/jersey-client.jar
/jersey-common.jar
/jersey-container-servlet.jar
/jersey-container-servlet-core.jar
/jersey-guava-2.8.jar
/jersey-server.jar
/web.xml
/META-INF
/MANIFEST.MF
Jersey-guava-2.8 is guava repackaged as jersey internal dependency , but only added as internal dependency after jersey 2.6.x version. The version jersey-container-servlet.jar that you have is before 2.6.x when jersey has dependency on Guava. So, the fix would be to use the latest jersey-container-servlet.jar and for all other dependencies or atleast the version after 2.6.x.