0

I'm having an issue getting a servlet to connect to a MySQL database on Linux (Ubuntu) server running Tomcat 7.

I have the code running perfectly fine on the dev environment (Windows 7, Tomcat 7). I make the WAR file in Eclipse with mysql-connector-java-5.1.34-bin.jar in WEB-INT/lib directory then deploy on Tomcat / Linux environment.

The WAR file unpacks fine and the static content is served without issue to the browser but, when initiating a task to interact with the database, I get an error code 500 internal server error and the localhost.2015-03-24.log gives the following error:

java.lang.NoClassDefFoundError: javax/websocket/Endpoint
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2944)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1208)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
    at websocket.drawboard.DrawboardContextListener.contextDestroyed(DrawboardContextListener.java:32)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5014)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5659)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1564)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: javax.websocket.Endpoint
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
    ... 17 more

I would also like to know how I can view the 17 other exceptions that are not being listed.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
SciGuyMcQ
  • 993
  • 6
  • 21

2 Answers2

0

Make sure you set the WebSocketServlet dependency as provided.

 <dependency>
      <groupId>javax.websocket</groupId>
      <artifactId>javax.websocket-api</artifactId>
      <version>1.1</version>
      <scope>provided</scope>
 </dependency>
Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
0

Thanks Arpit for your answer. However, adding the Maven dependenciy did not solve the problem. (On my Windows installation of Tomcat it worked all the time, on my Linux Tomcat not.)

As it turns out, the Debian (Ubuntu) version of Tomcat comes without the corresponding .jar (on Windows and normal Linux Tomcats it's included). Thus I tried adding the dependency with scope 'compile' to really add the .jar to my. war. No success either.

Finally the solution was to manually add the jars from the download of Tomcat from their website to Tomcat lib folder of the server.

Boato
  • 1
  • 1