开始学习Hibernate 3.5 - ant任务出现问题

5

我正在学习《Hibernate 3.5入门》,但遇到了一个问题。

当我运行ant exportDDL时,出现以下错误:

exportDDL:
   [htools] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
   [htools] 1. task: hbm2ddl (Generates database schema)
   [htools] SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
   [htools] SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
   [htools] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
   [htools] To get the full stack trace run ant with -verbose
   [htools] Problems in creating a AnnotationConfiguration. Have you remembered to add it to the classpath ?
   [htools] java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;

BUILD FAILED
C:\hibernate\project\build.xml:30: Problems in creating a AnnotationConfiguration. Have you
remembered to add it to the classpath ?

使用以下Ant任务:
<target name="exportDDL" depends="compile">
    <mkdir dir="${sql}"/>
    <htools destdir="${sql}">
        <classpath refid="classpath.tools"/>
        <annotationconfiguration
                configurationfile="${src}/hibernate.cfg.xml"/>
        <hbm2ddl drop="true" outputfilename="sample.sql"/>
    </htools>
</target>
<target name="compile">
    <javac srcdir="${src}" destdir="${bin}" classpathref="classpath.base"/>
</target>

这里发生了什么?ant compile可以正常工作,但exportDDL任务却不能。sl4j jar在类路径上,并且我下载了slf4j-simple-1.6.1.jar。有什么想法吗?
2个回答

18

这里解决你所需的问题

混合使用不同版本的slf4j工件可能会引起问题。例如,如果您正在使用slf4j-api-1.6.1.jar,则还应该使用slf4j-simple-1.6.1.jar,使用slf4j-simple-1.5.5.jar将无法正常工作。

通常,您应该确保slf4j-api版本与slf4j绑定版本匹配

在初始化时,如果SLF4J怀疑存在版本不匹配问题,它将发出有关怀疑的不匹配的警告。有关版本不匹配检测机制的详细信息,请参阅FAQ中的相关条目。


好的。看起来是sl4j-api-1.5.8。 - Stefan Kendall

3

以下是我遇到的一个例子,当您拥有不兼容的slf4j版本时,会出现SLF4J启动警告:

SLF4J:您的slf4j绑定请求的版本1.5.10与[1.6]不兼容 SLF4J:有关详细信息,请参见http://www.slf4j.org/codes.html#version_mismatch


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接