简体   繁体   中英

Tomcat7 on Linux Server Not Connecting to MySQL DB

Having an issue getting servlet to connect to mysql database on Linux (Ubuntu) server running tomcat7.

I have the code running perfectly fine on the dev environment (windows7, tomcat7). 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 initiate 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.

Thanks in advance.

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>

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 soluation was to manually add the jars from the download of Tomcat from their website to Tomcat lib folder of the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM