我正在尝试在glassfish 3.0.1上使用JPA设置hibernate 3.5.3;
我正在使用netbeans 6.9.1企业项目;我添加了所有必需的hibernate文件,一切都很好,除了记录...
我添加到项目类路径中,就像文档中说的那样(仅列出了与日志相关的jar):
-slf4j-API-1.5.8.jar
-slf4j-log4j12-1.5.8.jar
-log4j-1.2.16.jar
-log4j.properties看起来像:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=info, stdout
log4j.logger.org.hibernate.test=info
log4j.logger.org.hibernate.tool.hbm2ddl=debug
我还使用-Dlog4j.debug
JVM属性激活了调试。
我一部署就在服务器日志中得到这个:
SEVERE: log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
SEVERE: log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
SEVERE: log4j:ERROR [EarLibClassLoader :
urlSet = [URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/antlr-2.7.6.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/commons-collections-3.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/dom4j-1.6.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/gwt-servlet.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/hibernate3.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/javassist-3.9.0.GA.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/jta-1.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/log4j-1.2.16.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/slf4j-api-1.5.8.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/slf4j-log4j12-1.5.8.jar]
doneCalled = false
Parent -> org.glassfish.internal.api.DelegatingClassLoader@10ab6fa
] whereas object of type
SEVERE: log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [EarLibClassLoader :
urlSet = [URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/antlr-2.7.6.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/commons-collections-3.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/dom4j-1.6.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/gwt-servlet.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/hibernate3.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/javassist-3.9.0.GA.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/jta-1.1.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/log4j-1.2.16.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/slf4j-api-1.5.8.jar, URLEntry : file:/C:/Users/Bogdan/Documents/NetBeansProjects/GwtCms/dist/gfdeploy/GwtCms/lib/slf4j-log4j12-1.5.8.jar]
doneCalled = false
Parent -> org.glassfish.internal.api.DelegatingClassLoader@91cd46
].
SEVERE: log4j:ERROR Could not instantiate appender named "stdout".
SEVERE: log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
关于如何解决此问题的任何想法?谢谢!
修改
我试图从我的项目中删除log4j,因为Tushar Tarkas建议:
SEVERE: org/apache/log4j/Level
java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
EDIT2:解决方案
我不知道为什么,但是如果我复制/ domains / domain1 / lib中的log4j-1.2.16.jar文件就可以了。
EDIT3:
Pascal,这是GF部署的内容。
EnterpriseApplication1-ejb_jar >
.netbeans_automatic_build
.netbeans_update_resources
ejbs // classes for EJB
entities // classes for entities
log4j.properties
META-INF
EnterpriseApplication1-war_war >
index.jsp
META-INF
WEB-INF
META-INF
lib >
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
log4j-1.2.16.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
答案 0 :(得分:2)
我可以找到一些与类似问题相关的讨论。问题是glassfish版本3及更高版本。这些类似乎是由不同的类加载器加载的。
检查this。
答案 1 :(得分:0)
尝试使用Glassfish特定于应用程序的类加载。
将log4j.jar放入 [Glassfish的安装目录]。[PATH-TO-DOMAIN] / LIB / applibs。 您还可以创建一个新目录以保持清洁: [Glassfish的安装目录]。[PATH-TO-DOMAIN] / LIB / applibs / MY_APPLICATIONS_DEPENDENCIES
完成此操作后,必须指定在部署应用程序时加载log4j。 有两种选择: 1.管理控制台/ Web界面:在选项库中填写log4j的信息 2.将asadmin deploy命令与---- libraries选项一起使用,并指定逗号分隔的路径。有关详细信息,请参阅“Oracle GlassFish Server 3.1-3.1.1参考手册”。 (引自Oracle GlassFish Server 3.1应用程序开发指南)