问题
I'm trying to run org.hibernate.tool.ant.EnversHibernateToolTask as suggested in the rather terse guide to Envers (2nd line of table, Documentation has a link to a PDF). Here's my ant task tweaked so it successfully finds org.hibernate.tool.ant.EnversHibernateToolTask and org.hibernate.tool.ant.HibernateToolTask; now it can't find org.apache.tools.ant.Task and I have the sinking feeling I am doing something wrong.
<target name="schemaexport" depends="init"
description="Exports a generated schema to DB and file">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.EnversHibernateToolTask"
classpath=".;C:\appl\Java\jre6u13\lib\ext\envers-1.2.0.ga-hibernate-3.3.jar;C:\appl\Java\jre6u13\lib\ext\hibernate-tools.jar" />
<!--classpathref="${schema.classpath}"/>-->
<hibernatetool destdir=".">
<classpath>
<fileset refid="lib.hibernate" />
<path location="${build.dir}" />
</classpath>
<jpaconfiguration persistenceunit="ConsolePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="versioning-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
I've never done a custom ant task before so I'm probably missing something really simple. Any suggestions? I don't know what to put for the classpath in the hibernatetool task, which I can't find any documentation for beyond rudimentary javadoc.
edit: ok, some specific Q's to try to get to this piecemeal...
- which jar is
org.apache.tools.ant.Task
supposed to be in, and why can't ant find it? - where are the docs on how to use HibernateToolTask? (I assume EnversHibernateToolTask is supposed to work the same)
update (2009-06-18): OK, I finally screwed up my courage to try to make some progress on this and made some headway. I can get it to almost work by doing two things:
- run
ant schemaexport
from the command line, rather than from within Eclipse, to run myschemaexport
target. (ant in Eclipse can't seem to find org/apache/tools/ant/Task and I don't know how to set the Ant classpath in eclipse (distinct from the classpath in the taskdef item; somehow I have to tell ant to use a classpath to find its own damn class when it runs a custom task. this is insane.... grrr...) ensuring my classpath contains all the jars that I just take for granted by sticking in my JRE's
/lib/ext
directory:- envers-1.2.0.ga-hibernate-3.3.jar
- hibernate3.jar
- hibernate-tools.jar
- slf4j-log4j12-1.5.6.jar
- slf4j-api-1.5.6.jar
- log4j-1.2.15.jar
Now I get a new problem:
BUILD FAILED C:\deka\proj\java\test-database\build.xml:61: Problems in creating a configurati on for JPA. Have you remembered to add hibernate EntityManager jars to the class path ?
[[[[[scream]]]]]
update It appears I also needed
- hibernate-entitymanager.jar
- hibernate-annotations.jar
and I STILL get classloader errors:
BUILD FAILED
java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.hibernate.tool.ant.JPAConfigurationTask.createConfiguration(JPACo
nfigurationTask.java:33)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(Configurati
onTask.java:54)
How can I run this w/o having to use a J2EE server?!?!?!?!?!? What other JAR files do I need? I am really confused and frustrated.
update (2009-06-23): I finally got a successful build. Seems like you need:
* envers-1.2.0.ga-hibernate-3.3.jar
* hibernate3.jar
* hibernate-tools.jar
* slf4j-log4j12-1.5.6.jar
* slf4j-api-1.5.6.jar
* log4j-1.2.15.jar
* dom4j-1.6.1.jar
* hibernate-commons-annotations.ja
* a JAR containing JTA classes (Sun doesn't have a JAR file but you can download the [class files][3] yourself and make a JAR file out of it)
* a JAR containing JPA classes (I used toplink-essentials.jar from the glassfish project, per [this SO question][4])
* commons-logging-1.1.1.jar
* freemarker.jar
and made sure to use
<annotationconfiguration configurationfile="${some_path}/hibernate.cfg.xml"/>
instead of the <jpaconfiguration>
item included in the sample ant task. It still doesn't work properly though, I don't get the envers tables included. :(
回答1:
EnversHibernateToolTask extends HibernateToolTask. All I needed to do was the following:
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.EnversHibernateToolTask"
classpath="envers-1.2.0.ga-hibernate-3.3.jar" />
Otherwise it would be helpful to see the output of the ant file you've pasted.
回答2:
u might need ejb3-persistence-1.0.2.GA.jar
来源:https://stackoverflow.com/questions/952908/stumbling-blocks-galore-while-trying-to-run-org-hibernate-tool-ant-envershiberna