cyber101
cyber101

Reputation: 2994

Creating DDL scripts from JPA/Hibernate Annotation Classes Using ANT

I would like to generate SQL DDL scripts from Hibernate/JPA Annotation Classes using ANT.

Below is the ANT script that I wrote based on Hibernate Dev Docs URL: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/

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

Im getting ERROR taskdef class org.hibernate.tool.ant.HibernateToolTask cannot be found using the classloader AntClassLoader[]

I also checked to see if hibernate-tools.jar was actually in the path and it was (C:\Users\naim\Documents\NetBeansProjects\yourmarketnet\build\web\WEB-INF\lib\hibernate-tools.jar)

Can someone please tell me step by step how to fix/debug this issue , thanks.

Upvotes: 0

Views: 1310

Answers (1)

Alex Gitelman
Alex Gitelman

Reputation: 24722

Error message clearly tells you that ant can't find your tools. When you declare

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" >
   <classpath path="${build.dir}/web/WEB-INF/lib"/>
</taskdef>

it's already wrong because tool classes are not in directory but in jar. Secondly, your intent seems to be to use ${build.dir} as output location, so why would it contain tool classes? Anyway, you didn't even define this directory.

So if you really have your hibernate-tools.jar in web/WEB-INF/lib, you probably want something like

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" >
   <classpath path="web/WEB-INF/lib/hibernate-tools.jar"/>
</taskdef>

Note that it's relative to your project directory.

Upvotes: 1

Related Questions