Search code examples
javajarnoclassdeffounderror

NoClassDefFoundError when running Jar


I have this Problem. When i run my code in Intellij it works fine, but if i do an artifact and build the jar, it doesnt work. I think its caused by an extern library. Heres my output:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mindfusion/scheduling/Calendar
        at GUI.<init>(GUI.java:75)
        at Logfiles.main(Logfiles.java:13)
Caused by: java.lang.ClassNotFoundException: com.mindfusion.scheduling.Calendar
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 2 more

I know which Class it is but i dont know how to solve the Problem. Im really just a beginner. Could you please help me and explain it simple. Thank you

Edit:

After i build the artifact with extracted Libraries this Error comes : Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes


Solution

  • This error simply means the class file is not present in the jar.

    One possible solution is you can download jd-gui which is used to look at jars. You can use this to check if the class is present.

    Another solution is you can grep search the class in the jar with this simple command.

    grep -l "<class-name>" <jar-name>.jar
    

    if the class is not present in the jar file. you can add the class using jar command.

    jar -cvf <jar-absolute-location> <class-path>
    eg : jar -cvf GUI.jar com.mindfusion.scheduling.Calendar