Mysql/j Connector Unloads Mysteriously Under Tomcat 6/JDK 6

Thank you for taking time to look at my question.

I developing a Java WAR file intended for distribution to only one server at a time. So far, I have tested on 3 different servers with success, one Debian, one Ubuntu and the other, the Windows machine I'm developing on.

On the final deployment server, for some reason the app deploys fine, and upon each startup, runs well for about 3 minutes. Database connectivity works, everything runs fine. After 3 minutes however, I start seeing NoClassDefFoundError's consistently every time the app tries to access the DB.

I'm the following libraries with all of them packaged in the WAR file:

Mysql/j Connecter, latest version ActiveObjects, 0.8.2 Jasorb 1.3 Jython 2.5.1 (for some scripting) Tomcat 6.0.20 mod_python Apache

The error:

Exception in thread "Timer-4" java.lang.NoClassDefFoundError: com/mysql/jdbc/SQLError at com.mysql.jdbc.Util.handleNewInstance( at com.mysql.jdbc.ConnectionImpl.getInstance( at com.mysql.jdbc.NonRegisteringDriver.connect( at java.sql.DriverManager.getConnection( at java.sql.DriverManager.getConnection( at at at at at at at java.util.TimerThread.mainLoop( at Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.SQLError at org.apache.catalina.loader.WebappClassLoader.loadClass( 7) at org.apache.catalina.loader.WebappClassLoader.loadClass( 3) at java.lang.ClassLoader.loadClassInternal( ... 13 more

13.10.2009 18:55:24

Either your MySQL/J connector is somehow broken OR (more likely) you have another somewhere jar in your classpath that has only some of the classes from MySQL's JDBC driver. Either way, "com/mysql/jdbc/SQLError" class can't be found.

Your application runs fine the first few minutes, then when some error occurs the above class can't be loaded which throws the exception as posted. Check your entire classpath (CLASSPATH env. variable + tomcat's lib + webapp's lib) and see whether a) you actually do have SQLError in it and b) MySQL JDBC driver does not occur more than once.

Once the above is fixed, you'll get an actual error that's causing this and should be able to take it from there.

13.10.2009 19:12:44
Thank you for replying. I have tried removing the mysql/j connector from my WAR file and moving it to tomcat/libs. This produces a much larger stack trace that hopefully will be useful: Thank you so much!
samuraisam 13.10.2009 19:21:43
"this web application instance has been stopped already" message is highly suspicious - has you web app really been stopped (you can check that in tomcat's manager app)? If so, why? There are clearly some classloader issues there; the fact that moving your jdbc from war to tomcat/libs changed the behavior definitely points to that. What does your CLASSPATH contain (for user you're starting tomcat as)?
ChssPly76 13.10.2009 19:41:53
It get's more strange - The app isn't even deployed, and the MySQL/j connector isn't in the tomcat/lib directory however, the stack traces from the above post keep getting dumped to tomcat/logs/catalina.out. Is my tomcat installation borked? Thank you again for your help!
samuraisam 13.10.2009 19:56:24
You don't happen to have any other apps deployed to that tomcat instance, do you? Are you hot-deploying your app? At least for the purposes of troubleshooting I'd suggest you install fresh tomcat instance, deploy your WAR and then start tomcat with empty CLASSPATH (make sure JAVA_HOME / path are appropriate as well). That would at least limit possible culprits to your webapp's lib. The other thing to check is jre/lib/ext - make sure there are no rogue jars there. Once you get that working you can see what's different for your current Tomcat install.
ChssPly76 13.10.2009 20:08:48
No, this is supposed to be a fresh tomcat install (no other apps deployed either). I've tried all combinations of WAR/exploded war, hot loading/config loading... I'm guessing something was borked, so I'll try to re-install it myself and run with an empty CLASSPATH. Thank you so much for your help ChssPly76. I'll give your suggestions a try.
samuraisam 13.10.2009 20:24:11