首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate 4.0 hibernatetool taskdef错误

Hibernate 4.0 hibernatetool taskdef错误
EN

Stack Overflow用户
提问于 2011-10-20 03:39:17
回答 1查看 2.1K关注 0票数 4

我使用的是Hibernate 4.0.0.CR4,并尝试使用hibernate的Java持久性中的"Message“示例。我可以使用ant构建来编译和运行应用程序,但是当我尝试使用hibernatetool导出模式时,我得到了一个错误

build.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="HelloWorld" default="compile"  basedir=".">
    <property name="proj.name" value="HelloWorld"/>
    <property name="proj.version" value="1.0"/>

    <!-- Global properties for this build  -->
    <property name="src.java.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="build.dir" value="bin"/>

    <path id="project.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
            <include name="**/*.zip"/>
        </fileset>
    </path>

    <!-- Useful shortcuts -->
    <patternset id="meta.files">
        <include name="**/*.xml"/>
        <include name="**/*.properties"/>
    </patternset>

    <!-- Cleanup -->
    <target name="clean">
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}"/>
    </target>

    <!-- Compile Java source -->
    <target name="compile" depends="clean">
        <mkdir dir="${build.dir}"/>
        <javac
            srcdir="${src.java.dir}"
            destdir="${build.dir}"
            nowarn="on">
            <classpath refid="project.classpath"/>
        </javac>
    </target>

    <!-- Copy metadata to build classpath -->
    <target name="copymetafiles">
        <copy todir="${build.dir}">
            <fileset dir="${src.java.dir}">
                <patternset refid="meta.files"/>
            </fileset>
        </copy>
    </target>

    <!--Run HelloWorld -->
    <target name="run" depends="compile, copymetafiles"
        description="Build and run HelloWorld">
        <java fork="true"
            classname="hello.HelloWorld"
            classpathref="project.classpath">
            <classpath path="${build.dir}"/>
        </java>
    </target>
    <!-- SchemaExporter -->
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="project.classpath"/>
    <target name="schemaexport" depends="compile, copymetafiles"
        description="Exports a generated schema to DB and files">
        <hibernatetool destdir="${basedir}">
            <classpath path="${build.dir}"/>
            <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
            <hbm2ddl
                drop="true"
                create="true"
                export="true"
                outputfilename="helloworld-ddl.sql"
                delimiter=";"
                format="true"/>
        </hibernatetool>
    </target>
</project>

错误:

代码语言:javascript
复制
/home/student/workspace/HelloWorld/build.xml:61: taskdef A class needed by class org.hibernate.tool.ant.EnversHibernateToolTask cannot be found: org/hibernate/tool/ant/HibernateToolTask

以下是我的类路径上的jar: antlr-2.7.7.jar classmate-0.5.4.jar commons-collections 3.2.1.jar commons-logging-1.1.1.jar dom4j-1.6.1.jar hibernate-commons-annotations-4.0.0.CR2.jar hibernate-core-4.0.0.CR4.jar hibernate-envers-4.0.0.CR4.jar hibernate-jpa-2.0-api-1.0.1.Final.jar jandex-1.0.3.Final.jar jboss-transaction-api_1.1_spec-1.0.0.Final.jar -3.12.1.GA.jar jboss- hsqldb.jar -3.0.0.GA.jar jboss

在一些论坛上,我发现缺少的类是hibernate-tools.jar的一部分,但我在hibernate版本(http://sourceforge.net/projects/hibernate/files/hibernate4/4.0.0.CR4/)中找不到这个jar。

EN

回答 1

Stack Overflow用户

发布于 2012-06-15 17:19:26

您应该将节点设置在

代码语言:javascript
复制
<target name="schemaexport" depends="compile, copymetafiles"
    description="Exports a generated schema to DB and files">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
        classpathref="project.classpath"/>

    <hibernatetool destdir="${basedir}">
        <classpath path="${build.dir}"/>
        <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>
        <hbm2ddl
            drop="true"
            create="true"
            export="true"
            outputfilename="helloworld-ddl.sql"
            delimiter=";"
            format="true"/>
    </hibernatetool>
</target>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7827106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档