0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Edited my original post based on your comment <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask.jar"> <classpath path="${build.dir}/web/WEB-INF/lib/hibernate-tools.jar"/> </taskdef> And I checked the path ${build.dir}/web/WEB-INF/lib/hibernate-tools.jar , the hibernate-tools.jar actually exists

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.