尝试运行 org.hibernate.tool.ant.EnversHibernateToolTask 时遇到了很多绊脚石 [英] stumbling blocks galore while trying to run org.hibernate.tool.ant.EnversHibernateToolTask
问题描述
我正在尝试按照 中的建议运行 org.hibernate.tool.ant.EnversHibernateToolTaskEnvers 的简洁指南(表格的第二行,文档有一个指向 PDF 的链接).这是我的 ant 任务调整后成功找到 org.hibernate.tool.ant.EnversHibernateToolTask 和 org.hibernate.tool.ant.HibernateToolTask;现在它找不到 org.apache.tools.ant.Task 并且我有一种下沉的感觉,我做错了什么.
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>
我以前从未做过自定义 ant 任务,所以我可能遗漏了一些非常简单的东西.有什么建议?我不知道在 hibernatetool 任务中为类路径放置什么,除了 基本 javadoc.
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...
org.apache.tools.ant.Task
应该在哪个 jar 中,为什么 ant 找不到它?- 关于如何使用 HibernateToolTask 的文档在哪里?(我假设 EnversHibernateToolTask 应该可以正常工作)
- 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):好吧,我终于鼓起勇气尝试在这方面取得一些进展并取得了一些进展.我可以通过做两件事来让它几乎工作:
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:
- 从命令行运行
ant schemaexport
,而不是从 Eclipse 中运行,以运行我的schemaexport
目标.(Eclipse 中的 ant 似乎找不到 org/apache/tools/ant/Task 并且我不知道如何在 Eclipse 中设置 Ant 类路径(与 taskdef 项中的类路径不同;不知何故我必须告诉 ant当它运行自定义任务时使用类路径找到它自己该死的类.这太疯狂了.... grrr...) 通过粘贴在 JRE 的
/lib/ext
目录中,确保我的类路径包含我认为理所当然的所有 jar:
- 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:
构建失败C:\deka\proj\java\test-database\build.xml:61:创建配置的问题对于 JPA.你记得添加吗休眠 EntityManager jars 到类路径?
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]]]]]
更新看来我也需要
- 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)
如何在不使用 J2EE 服务器的情况下运行此程序?!?!?!?!?!?我还需要哪些其他 JAR 文件?我真的很困惑和沮丧.
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.
更新 (2009-06-23):我终于成功构建了.好像你需要:
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
并确保使用
<annotationconfiguration configurationfile="${some_path}/hibernate.cfg.xml"/>
而不是示例 ant 任务中包含的
项.尽管如此,它仍然无法正常工作,我没有包含 envers 表.:(
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. :(
推荐答案
EnversHibernateToolTask 扩展了 HibernateToolTask.我需要做的就是以下几点:
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" />
否则,查看您粘贴的 ant 文件的输出会很有帮助.
Otherwise it would be helpful to see the output of the ant file you've pasted.
这篇关于尝试运行 org.hibernate.tool.ant.EnversHibernateToolTask 时遇到了很多绊脚石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!