I wrote a maven web service which refers to another project. The web service itself only contains 2 pom entries:
- jersey-container-servlet: 2.13
- native Project (Project 1)
web service POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Webservice</groupId>
<artifactId>Webservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/Webservice</path>
<update>true</update>
<url>http://server.name:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat</password>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.13</version>
</dependency>
<dependency>
<groupId>lu.group.id</groupId>
<artifactId>Project1</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
</project>
Project 1, is also a maven Project and only has 1 pom entry, another native project (Let's call it Project 2).
Project 2 is again a maven project and its pom file contains 5 entries:
- lang-guess: 0.0.7
- Stanford-corenlp: 3.5.2
- stanford-corenlp: 3.5.2 : models
- mysql-connector-java : 5.1.34
- language-de: 3.0
The Web service runs perfectly on my local installed Tomcat 8 in Eclipse. However, when I export the web service from Eclipse (War file) and deploy it on my Tomcat server, I receive a java.lang.NoClassDefFoundError
when I try to run the web service. I already tried several things I found on the net:
- Cleaning the project before building a war
- Maven update
- Setting %classpath% of my tomcat server to the project root directoy
- Adding both jars from Project 1 and Project 2 into tomcat/libs
- Removed all jars from the web service and deployed an incorrect (notrunning) project (Normally I should get a
ClassNotFoundExeception
or similar?) - Add Project 1 to Deployment Assembly in Eclipse
In addition I read and tried many solutions already on several stackoverflow questions:
- java.lang.NoClassDefFoundError
- NoClassDefFoundError in web application running on Tomcat 7
- java.lang.NoClassDefFoundError: apache-tomcat-7.0.25
- Error: Servlet Jar not Loaded…
- validateJarFile(servlet-api.jar)
- exception in thread 'main' java.lang.NoClassDefFoundError:
- java.lang.NoClassDefFoundError when i run java file from terminal
- Setting up java classpath and java_home correctly in Ubuntu
All in all, nothing worked and the error java.lang.NoClassDefFoundError
persist... I don't know what else to try so I am glad for any help! Thank you in advance :)
Mention able are maybe the server information:
- Tomcat Version: 8.0.30
- JVM Version: 1.8.0_66-b17
- OS: Linus (Ubuntu)
In addition, two other maven web services I wrote, successfully run on this server! So I think it could not be a server configuration problem?
Full stack trace is the following:
java.lang.NoClassDefFoundError: Could not initialize class org.jvnet.hk2.internal.ServiceLocatorImpl
org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.initialize(ServiceLocatorGeneratorImpl.java:67)
org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl.create(ServiceLocatorGeneratorImpl.java:102)
org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.internalCreate(ServiceLocatorFactoryImpl.java:270)
org.glassfish.hk2.internal.ServiceLocatorFactoryImpl.create(ServiceLocatorFactoryImpl.java:230)
org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:138)
org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:123)
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
UPDATE: Due to the fact that I still found no solution, I simply copy pasted Project 1 and Project 2 to my web service. The web service still runs fine on localhost Tomcat but still the same crap NoClassDefFoundError
error on Tomcat Server... Now I am REALLY REALLY out of ideas.