简体   繁体   English

线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/log4j/Logger 在创建可执行 JAR 后,但这是一个 JAVA 项目

[英]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.我有一个 JAVA (awt) 项目来构建桌面基础实用程序。 When I try to run this from other machine with only JRE Installed this is giving an exception as当我尝试从仅安装了 JRE 的其他机器上运行它时,这是一个异常

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.这里我没有使用 Maven 项目,而是直接从 Eclipse 创建一个可执行 JAR。 All though I see the JAR for log4J (log4j-1.2.17.jar) in the MANIFEST.尽管我在清单中看到了 log4J (log4j-1.2.17.jar) 的 JAR。 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 (其他机器只有 JRE 而不是 JDK)按照我用来运行 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?例外是说您没有在类路径中找到 log4j 依赖项:您是否在与放置 jar 的文件夹相同的文件夹中提供 log4j.jar?

It is not so easy to reference other jars when running an application as java -jar yourApp.jar ...在运行应用程序时引用其他 jars 并不容易,如java -jar yourApp.jar ...

  • You can take a look to this post about this referencing a jar when running another one;您可以查看这篇关于在运行另一个 jar 时引用 jar 的帖子
  • If you want to investigate about MANIFEST usage, take a look here ;如果您想调查 MANIFEST 的用法,请查看此处

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 ).但是,我建议您使用 maven(或手动执行)导出一个 fatjar,并将所需的依赖项打包到其中(查看maven-assembler插件或Eclipse 可运行的 jar 导出选项)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“JavaFX 应用程序线程”中的 JavaFx 异常 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/log4j/Logger - JavaFx Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / log4j / Layout-从命令提示符处运行Runnig JAR时 - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/Layout - While Runnig JAR from Command Prompt 线程“主”中的异常java.lang.NoClassDefFoundError:org / apache / logging / log4j / LogManager - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / logging / log4j / message / Message - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/Message 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/log4j/ProvisionNode - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/ProvisionNode Scala:线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / log4j / LogManager - Scala : Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/LogManager 线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/log4j/Layout - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/Layout Log4j 迁移-异常 java.lang.NoClassDefFoundError: org/apache/log4j/FileAppender - Log4j migration -Exception java.lang.NoClassDefFoundError: org/apache/log4j/FileAppender Elasticsearch Java API错误java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger - Elasticsearch java api error java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger - java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM