Tuesday, November 13, 2012

Maven and The "exception in thread main java.lang.noclassdeffounderror"



This a tip for that situation when everything was checked and looks fine but eventually doesn't work!  : )

Short story
If you are sure that your configuration is correct and has also tried everything, then try creating a new project from scratch and after migrate the code.



Long story

Issue:

Output:

Exception in thread "main" java.lang.NoClassDefFoundError: validation/schema/XasValidator
Caused by: java.lang.ClassNotFoundException: validation.schema.XasValidator
  at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: validation.schema.XasValidator. Program will exit.



Solution

After checking all possible configurations in project, including of course the pom.xml file, the problems still remained.

The solution came from creating a new project from scratch.

mkdir xalValidator
cd xalValidator
mvn archetype:create -DgroupId=com.adr -DartifactId=xalValidator -DpackageName=validator.schema -Dversion=1.0

After I copied the pom.xml file from the deffective project to the new one.
Then, I migrated the code from the old to the new project.
Finally I tested the project generating the jar file.
Yesss, success.

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...