Search code examples
javatomcattomcat7classloader

Tomcat classloader is not working


I need your help. I am facing unusual problem dealing with Tomcat classloader. I have a WAR and inside the WAR there's a third-party JAR that has native methods. The WAR successfully deployed in a development server for the first time and had been running for about 3 months.

Last week, I did some code refactoring and wanted to deploy the updated WAR, so I delete the old instance and deployed WAR. But now after the redeployment, I always face NoClassDefFoundError. I redeploy the WAR for several times, and the result is same, NoClassDefFoundError.

Oddly, when I deployed the updated WAR in my laptop also use Tomcat, it works fine. My co-worker also tried to deployed in his laptop using Tomcat, it works fine.

I had deleted files inside work directory, but still NoClassDefFoundError appeared. I had turn off the Tomcat, delete the instance on webapp folder, copy the updated WAR again in webapp folder, turn on Tomcat again, but still the error shows up.

What's wrong with the Tomcat in the development server?


Solution

  • You can only register a native library once in the lifetime of a JVM. I suspect that when you updated the WAR, it tried to register the native library again, that failed and that in turn lead to the NoClassDefFoundError. That a restart of the Tomcat server fixed it is consistent with this theory.

    If you ship a WAR that contains a native library then the safest course is to restart Tomcat everytime you need to update the app.