0

我正在尝试使用 ANT 从我的 Hibernate 注释 bean 生成 SQL DDL,根据我创建了以下 Ant 脚本的休眠工具文档:

<?xml version="1.0" encoding="UTF-8"?>
<project name="yourmarketnet" default="all" basedir=".">
<property name="build.dir" value="C:/Users/naim/Documents/NetBeansProjects/yourmarketnet/build" />
<target name="ddl_generation">
<!-- paths to required jars  -->
<path location="web/WEB-INF/lib/hibernate-annotations.jar" />
<path location="web/WEB-INF/lib/ejb3-persistence.jar" />
<path location="web/WEB-INF/lib/hibernate-entitymanager.jar" />
<path location="web/WEB-INF/lib/javaassist.jar" />
<path location="web/WEB-INF/lib/hibernate-tools.jar"/>
<path location="web/WEB-INF/lib/hibernate-entitymanager.jar" />
<path location="web/WEB-INF/lib/jboss-archive-browsing.jar" />
<path location="web/WEB-INF/lib/javaassist.jar" />

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
    </taskdef>
    <classpath>
    <!-- path of annotation beans -->
<path location="${build.dir}/web/WEB-INF/classes/com/yourmarketnet/beans" />
</classpath>
<!-- output destination -->
<hibernatetool destdir="${build.dir}">
<!-- were the annotation beans files are located-->
<!-- list exporters here -->
<hbm2ddl
export="false"
update="false"
drop="true"
create="true"
outputfilename="myApps.ddl"
delimiter=";"
format="false"
haltonerror="true"/>
</hibernatetool>
</target>
</project>

但是我收到以下错误:

使用类加载器 AntClassLoader[] 找不到 taskdef 类 org.hibernate.tool.ant.HibernateToolTask

我检查了我的 /lib & 文件夹,并且存在类路径 hibernate-tools。

4

1 回答 1

1

在我的 ant 脚本中,我通常使用 lib 文件夹的绝对路径定义一个名为 lib.dir 的属性,并使用该标签来加载我所有的 jar,因为某种原因的相对路径对我来说一直是个问题。对你来说可能也值得一试。

<property name="lib.dir" value="C:\path\to\project\WebContent\WEB-INF\lib"/>
<property name="jdk.home" value="C:\path\to\jdk" />
<path id="project.classpath">
    <fileset dir="${lib.dir}">
        <include name="*.jar"/>
    </fileset>
    <pathelement location="${jdk.home}/jre/javaws/javaws.jar"/>
    <pathelement location="${jdk.home}/jre/lib/charsets.jar"/>
    <pathelement location="${jdk.home}/jre/lib/ext/dnsns.jar"/>
    <pathelement location="${jdk.home}/jre/lib/ext/ldapsec.jar"/>
    <pathelement location="${jdk.home}/jre/lib/ext/localedata.jar"/>
    <pathelement location="${jdk.home}/jre/lib/ext/sunjce_provider.jar"/>
    <pathelement location="${jdk.home}/jre/lib/im/indicim.jar"/>
    <pathelement location="${jdk.home}/jre/lib/im/thaiim.jar"/>
    <pathelement location="${jdk.home}/jre/lib/jce.jar"/>
    <pathelement location="${jdk.home}/jre/lib/jsse.jar"/>
    <pathelement location="${jdk.home}/jre/lib/plugin.jar"/>
    <pathelement location="${jdk.home}/jre/lib/rt.jar"/>
    <pathelement location="${jdk.home}/jre/lib/sunrsasign.jar"/>
    <pathelement location="${jdk.home}/lib/dt.jar"/>
    <pathelement location="${jdk.home}/lib/htmlconverter.jar"/>
    <pathelement location="${jdk.home}/lib/tools.jar"/>
</path>
...
// Rest of your build file
...
于 2012-06-03T02:37:48.587 回答