简体   繁体   中英

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger after creating an executable JAR but this is a JAVA Project

I have a JAVA (awt) Project to build a desktop base utility. When I try to run this from other machine with only JRE Installed this is giving an exception as

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at DataProcessor.DataProcessor.App.<clinit>(App.java:73)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Unknown Source)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.base/java.net.URLClassLoader.findClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)  

here I am not using a maven project, creating an executable JAR directly from eclipse. All though I see the JAR for log4J (log4j-1.2.17.jar) in the MANIFEST. But this is giving an exception when I try to run it from other machines. ( Other machines has only JRE not JDK) following command I am using to run JAR

C:\Users\<username>\Desktop\Utility\latest>"C:\Program Files\Java\jre1.8.0_161\bin\java.exe" -jar Utility.jar

The exception is sayin' that you don't have the log4j dependency found on your class path: are you providing the log4j.jar in the same folder as the one in which your jar is placed?

It is not so easy to reference other jars when running an application as java -jar yourApp.jar ...

  • You can take a look to this post about this referencing a jar when running another one;
  • If you want to investigate about MANIFEST usage, take a look here ;

However, i suggest you to use maven (or do it manually) exporting a fatjar with the needed dependencies packaged into (take a look to maven-assembler plugin or Eclipse runnable jar export options ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM