我有以下文件夾結構...如何將log4j.properties和log4j.jar添加到可執行文件jar ..?
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
不應該包含'log4j-1.2.15.jar'而不是'log4j-1.2.17.jar'? – Neo 2015-04-04 07:42:17
對不起,這是錯字錯誤 – 2015-04-04 07:45:40
我需要在manifest.txt中給「prop/log4.properties」而不是「prop」嗎? – 2015-04-04 07:51:52