我有以下文件夹结构...
MyApp
|com
|lib
|--- log4j-1.2.17.jar,mysqlconn.jar,jcalendar-1.4.jar,poi-3.9.jar
|prop
|---log4j.properties
|manifest.txt
manifest.txt:
Main-Class: com.java.test.WelcomeScreen
Class-Path: prop lib/jcalendar-1.4.jar lib/log4j-1.2.17.jar lib/mysql-connector-java-5.0.8-bin.jar lib/poi-3.9.jar
我正在创建可执行jar,如下所示:
C:\Users\Administrator\Desktop\MyApp>jar -cvfm myapp.jar manifest.txt com/java/test/*.class com/java/db/*.class
然后跑步:
C:\Users\Administrator\Desktop\MyApp>java -jar myapp.jar
我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.java.test.LoginForm.<clinit>(LoginForm.java:17)
at com.java.test.WelcomeScreen.main(WelcomeScreen.java:134)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
答案 0 :(得分:0)
您需要在清单末尾添加一个空行。
在log4j.properties
存在的情况下,只包括目录就可以了。
我打算建议将log4.properties放在与主jar文件相同的路径中并添加&#34;。&#34;到类路径。但是看起来像在目录末尾添加/
就像OP找到的那样工作。