我的项目中有以下罐子:
antlr.jar
commons.collections-3.2.1.jar
dom4j-1.6.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.0.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.12.1.GA.jar
jboss-logging.3.1.0.cr2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
log4j-1.2.16.jar
slf4j-api-1.6.4.jar
slf4j-log4j12-1.6.4.jar
发生异常的代码:
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL url = loader.getResource("log4j.properties");
System.out.println(url);
PropertyConfigurator.configure(url);
System.out.println(url) 为:
file:/D:/me/HibernateProject/build/classes/log4j.properties
该文件存在,浏览器可以浏览该文件。
log4j.properties 文件包含以下内容:
http://www.javatpoint.com/hibernate-logging-by-log4j-using-properties-file
例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator
at com.pkm.commands.UpdateUser.doWork(UpdateUser.java:29)
at com.pkm.commands.UpdateUser.main(UpdateUser.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.PropertyConfigurator
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
Java Result: 1