0

I wrote a maven web service which refers to another project. The web service itself only contains 2 pom entries:

  1. jersey-container-servlet: 2.13
  2. 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:

  1. lang-guess: 0.0.7
  2. Stanford-corenlp: 3.5.2
  3. stanford-corenlp: 3.5.2 : models
  4. mysql-connector-java : 5.1.34
  5. 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:

  1. Cleaning the project before building a war
  2. Maven update
  3. Setting %classpath% of my tomcat server to the project root directoy
  4. Adding both jars from Project 1 and Project 2 into tomcat/libs
  5. Removed all jars from the web service and deployed an incorrect (notrunning) project (Normally I should get a ClassNotFoundExeception or similar?)
  6. Add Project 1 to Deployment Assembly in Eclipse

In addition I read and tried many solutions already on several stackoverflow questions:

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.

Community
  • 1
  • 1
Flu
  • 111
  • 10
  • Can you successfully build your *.WAR file with the command line e.g. with `mvn clean package` ? – eztam Jan 22 '16 at 09:06
  • Hi. No it gives me an error saying that it does not find the jar. However, it refers to an old jar "Project1:0.0.1-SNAPSHOT". However, I renamed it to `"4.0.1, lu.group.id project1`. Why don't he know that by cleaning, updating maven after renaming? And how do I make maven that clear? – Flu Jan 22 '16 at 09:25
  • I found out how to tell maven to find the jar here [http://stackoverflow.com/questions/4701532/force-maven-update]. With your command `mvn clean package`, the build is now a success, but it does not solved the problem unfortunately... same error `java.lang.NoClassDefFoundError`... Any other idea? – Flu Jan 22 '16 at 09:51
  • I also tried it now on the way explained here http://crunfy.me/14Kezhx. However, the result is still the same than simply exporting the war by right clicking on the project --> Export --> War File. `java.lang.NoClassDefFoundError`... – Flu Jan 22 '16 at 10:16
  • It's surely not the best practice solution, but you could simply add the dependency that provides the class `org.jvnet.hk2.internal.ServiceLocatorImpl` also to your 2nd pom.xml. – eztam Jan 22 '16 at 12:13
  • It makes no difference and to be honest, I am not surprised it doesn't. Because every library is only present once in WEB-INF\lib after exporting the war ;) – Flu Jan 22 '16 at 12:46

1 Answers1

0

I solved my problem. Don't ask me what it was, I simply started from scratch, copy pasted the content I had one by one in the new web project and by exporting the war file, it worked like a charm on the first try...

Anyway, thanks alot for the help.

Flu
  • 111
  • 10