0

Here is an absurd scenario because I'm totally clueless why is this happening.

I have created a Java servlet, (maven) packaged as war to be deployed on Tomcat server. It works fine on 2 test machines (believe me) but when it is moved on another machine, any hit on that api gives NoClassDefFoundError for a particular class.

I've checked the unpacked Project directory in the webapps folder, and it contains that class.

What can be the reasons for this? I've checked all that I could but no clues anywhere. I know myself that it is not very clear a question but this is all I have.

Any other details, if required, ask for it in the comments.

Edit: (one more detail)

The Tomcat version is upgraded in this new machine...Previous machines have Apache Tomcat/7.0.59. This has Apache Tomcat/8.0.33. Can this be the problem?

EDIT:

I'm still not sure of the problem. After trying to find the issue for many hours, I re-configured the machine...re installed jdk and Tomcat and deployed on this and it worked.

vish4071
  • 5,135
  • 4
  • 35
  • 65

1 Answers1

1

My guess is that all the classes are there, but somewhere in the war file, there is class that uses another class that is in the classpath of the native, working machine, but not the other. NoClassDefinition is different from ClassNotFound, so the class is probably there (it should not be missing). Unfortunately, it sounds like there is a dependency that is not in the native war file, but still runs and compiles because it's in the native machine classpath.

Check your .bash_profile or wherever you export classpaths and you'll probably find some JAR file you need to put in the WAR.

Why am I getting a NoClassDefFoundError in Java?

Alexander Kleinhans
  • 5,950
  • 10
  • 55
  • 111
  • But the project has few dependencies which are put in `pom.xml`...no Custom jars are included. There are 4 packages though, which talk among themselves, and they are there in classes folder as they should be. – vish4071 May 10 '16 at 07:31
  • Again, only a hypothesis. `NoClassDefFoundError` does not mean the class is not there, it is defiantly there if you unpack the war file, otherwise you would be seeing `ClassNotFound`. Some class BEING USED the class inside the war file (which is not missing) is USING another class that is NOT in the war file, hence the DEFINITION is missing, not the CLASS. My guess is that it is in the `classpath` of the native machine, which is why it originally resolved correctly, but not on the new machine where the `classpath` is different. – Alexander Kleinhans May 10 '16 at 07:38