试图运行org.hibernate.tool.ant.EnversHibernateToolTask​​时遇到难题 [英] stumbling blocks galore while trying to run org.hibernate.tool.ant.EnversHibernateToolTask

查看:109
本文介绍了试图运行org.hibernate.tool.ant.EnversHibernateToolTask​​时遇到难题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照建议的方式运行org.hibernate.tool.ant.EnversHibernateToolTask Envers的简要指南(表格的第二行,文档链接至PDF)。这里是我的蚂蚁任务调整,所以它成功找到org.hibernate.tool.ant.EnversHibernateToolTask​​和org.hibernate.tool.ant.HibernateToolTask​​;现在它无法找到org.apache.tools.ant.Task,并且我有沉没的感觉,我做错了什么。

 < target name =schemaexportdepends =init
description =将生成的模式导出到数据库和文件>
< 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/>
< / classpath>
< jpaconfiguration persistenceunit =ConsolePU/>
< hbm2ddl
drop =false
create =true
export =false
outputfilename =versioning-ddl.sql
delimiter =;
format =true/>
< / hibernatetool>
< / target>

我从来没有做过自定义的ant任务,所以我可能错过了一些非常简单的东西。有什么建议么?我不知道在hibernatetool任务中为classpath放置什么,我无法找到超出基本的javadoc



编辑:确定,一些特定的Q可以尝试到这种零碎......


  1. 哪个jar是 org.apache.tools .ant.Task 应该在,为什么不能找到它?

  2. 其中是关于如何使用HibernateToolTask​​的文档? (我假设EnversHibernateToolTask​​应该是一样的)

更新(2009-06-18):好吧,我终于鼓起勇气尝试在这方面取得一些进展并取得了一些进展。我可以通过做两件事来完成它:


  1. 运行 ant schemaexport 从命令行而不是从Eclipse内部运行我的 schemaexport 目标。 (在Eclipse中的蚂蚁似乎无法找到org / apache / tools / ant / Task,我不知道如何在eclipse中设置Ant类路径(与taskdef项目中的classpath不同;不知何故我必须告诉ant使用类路径在运行自定义任务时找到它自己的该死的类,这是疯狂的.... grrr ...)
    确保我的类路径包含所有的jar通过坚持我的JRE的 / lib / ext 目录: > envers-1.2.0.ga-hibernate-3.3.jar

  2. hibernate3.jar

  3. hibernate-tools.jar

  4. slf4j-log4j12-1.5.6.jar

  5. slf4j-api-1.5.6.jar

  6. log4j-1.2.15 .jar


现在我遇到一个新问题:


BUILD FAILED
C:\deka\proj\java\test-database\build.xml:61:
在为JPA创建
的配置时遇到的问题您是否记得添加
hibernate EntityManager jars to
class path?


[[[[scream]]]]]



更新看来我还需要

$ ul

  • hibernate-entitymanager.jar

  • hibernate-annotations.jar



  • 和我仍然得到classloader错误:

      BUILD FAILED 
    java.lang.Class.getDeclaredConstructors0(Native())中的java.lang.NoClassDefFoundError:javax / persistence / PersistenceException
    方法)
    在java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)$ b $在java.lang.Class.getConstructor0(Class.java:2699)$ b $在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)
    在org.hibernate.tool.ant.ConfigurationTask.getConfiguration(Configurati
    onTask.java:54)

    如何运行这个不必使用J2EE服务器?!?!?!?!?!?我需要哪些其他JAR文件?我非常困惑和沮丧。


    $ b 更新(2009-06-23):我终于成功了建立。看起来像你需要:

    $ $ p $ $ code 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
    *包含JTA类的JAR(Sun没有JAR文件,但您可以下载[ class文件] [3]自己并创建一个JAR文件)
    *一个包含JPA类的JAR(我使用了glassfish项目的toplink-essentials.jar,根据[this SO question] [4])
    * commons-logging-1.1.1.jar
    * freemarker.jar

    并确保使用

     < annotationconfiguration configurationfile =$ {some_path} /hibernate.cfg.xml/> 

    而不是< jpa配置> 项目包含在示例ant任务中。它仍然无法正常工作,但我没有收到envers表。 :

    解决方案

    EnversHibernateToolTask​​扩展了HibernateToolTask​​,我需要做的是以下几点:

     < taskdef name =hibernatetool
    classname =org.hibernate.tool.ant.EnversHibernateToolTask​​
    classpath =envers-1.2。 0.ga-hibernate-3.3.jar/>

    否则,输出你粘贴的ant文件。


    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...

    1. which jar is org.apache.tools.ant.Task supposed to be in, and why can't ant find it?
    2. 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:

    1. run ant schemaexport from the command line, rather than from within Eclipse, to run my schemaexport 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...)
    2. 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. :(

    解决方案

    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.

    这篇关于试图运行org.hibernate.tool.ant.EnversHibernateToolTask​​时遇到难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆