休眠 - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20177833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:46:15  来源:igfitidea点击:

Hibernate - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

javahibernateantlog4jruntime-error

提问by nazar_art

I tried to run easy program with hibernate and HSQLDB.

我尝试使用 hibernate 和 HSQLDB 运行简单的程序。

I'm using log4jfor this project with log4j.properties:

我正在log4j为这个项目使用log4j.properties

# Direct log messages to stdout
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} %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=INFO, stdout

# Hibernate logging options (INFO only shows startup messages)
log4j.logger.org.hibernate=INFO

# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=INFO

and all is build with Ant, build file you can see here.

一切都是用 构建的Ant,你可以在这里看到构建文件。

But when I run schemaexporttarget I caught next error:

但是当我运行schemaexporttarget 时,我发现了下一个错误:

BUILD FAILED
/home/nazar_art/workspace/Persistance/build.xml:64: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

schemaexport error

模式导出错误

But I hasn't use slf4jwhy this caused?

但是我一直没有使用slf4j为什么会这样造成?

here is my content of libfolder with all jars that It uses:

这是我lib使用的所有 jar 文件夹的内容:

lib struckture

自由敲击

I couldn't figure out why does this happen?

我无法弄清楚为什么会发生这种情况?

Here is better project structure:

这是更好的项目结构:

project struckture

项目建设

EDIT:

编辑:

I added slf4j-api-1.6.1.jarand slf4j-log4j12-1.6.1.jarbut it throws:

我添加了slf4j-api-1.6.1.jarslf4j-log4j12-1.6.1.jar但它抛出:

BUILD FAILED /home/nazar_art/workspace/Persistance/build.xml:64: java.lang.NoClassDefFoundError: javax/persistence/EntityListeners

构建失败 /home/nazar_art/workspace/Persistance/build.xml:64: java.lang.NoClassDefFoundError: javax/persistence/EntityListeners

you can see here how it looks:

你可以在这里看到它的样子:

entity listeners

实体监听器

How to solve this trouble?

如何解决这个烦恼?

采纳答案by noone

Hibernate uses SLF4Jinternally to do its own logging. It is an abstraction layer on top of different logging implementations. Frameworks like using this facade because in this case you still stay independend from certain implementations. You can also make it work with log4j. Follow this tutorialto make it work together.

Hibernate 在内部使用SLF4J来做自己的日志记录。它是不同日志实现之上的抽象层。框架喜欢使用这个门面,因为在这种情况下你仍然独立于某些实现。你也可以让它与 log4j 一起工作。按照本教程使其协同工作。

回答by Bimalesh Jha

Hibernate internally uses SLF4J for logging. Read the setup instructions here: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#tutorial-firstapp-setupYou need to keep SLF4J jaron the build and runtime classpath.

Hibernate 内部使用 SLF4J 进行日志记录。在此处阅读设置说明:http: //docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#tutorial-firstapp-setup您需要保持SLF4J jar构建和运行时类路径。