javaeclipsenoclassdeffounderrorjsprit

Cannot run the code due to java.lang.NoClassDefFoundError


I am investigating the jsprit library. For this I just created a new project in Eclipse and copied-pasted the demo example class. Then I added all jars to the path, including log4j-1.2.17.jar. Nevrtheless I cannot execute the demo code due to the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
    at jsprit.core.problem.vehicle.VehicleImpl$Builder.<clinit>(VehicleImpl.java:108)
    at com.test.jsprit.main(jsprit.java:49)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

What does it actually mean and how to solve this issue? Does it mean that some other *.jar file is missed?

UPDATE:

The error occurs at the following line:

Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");

Solution

  • You are using the wrong version of the log4j lib. You need the 2.x version.

    See:

    LogManager (Version 1.x)

    LogManager (Version 2.x)