为什么我会收到错误“只能从 URI 定位到 antlib URI,而不是 URI”? 当尝试在我的 build.xml 中运行休眠工具时

发布于 2024-07-17 07:16:54 字数 3565 浏览 11 评论 0原文

我正在尝试在 ant 构建中运行 hibernate 工具,以从 JPA 注释生成 ddl。 Ant 在 taskdef 标签上死亡。 我尝试过 ant 1.7、1.6.5 和 1.6,但没有成功。 我在日食和外部都尝试过。 我尝试过将所有 hbn jar 包含在 hibernate-tools 路径中,但没有。 请注意,我的构建文件基于这篇文章:

Hibernate JPA 到 DDL 命令行工具

我正在 Ubuntu 8 上运行 eclipse 3.4、WTP 3.0.1 和 MyEclipse 7.1。Build.xml

<project name="generateddl" default="generate-ddl">

<path id="hibernate-tools">
    <pathelement location="../libraries/hibernate-tools/hibernate-tools.jar" />
    <pathelement location="../libraries/hibernate-tools/bsh-2.0b1.jar" />
    <pathelement location="../libraries/hibernate-tools/freemarker.jar" />
    <pathelement location="../libraries/jtds/jtds-1.2.2.jar" />
    <pathelement location="../libraries/hibernate-tools/jtidy-r8-20060801.jar" />

</path>

<taskdef classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernate-tools"/>

<target name="generate-ddl" description="Export schema to DDL file"> 
<!-- compile model classes before running hibernatetool -->

    <!-- task definition; project.class.path contains all necessary libs 
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path" />
    -->

    <hibernatetool destdir="sql"> 

        <!-- check that directory exists -->
        <jpaconfiguration persistenceunit="default" />

        <classpath>

            <dirset dir="WebRoot/WEB-INF/classes">
                <include name="**/*"/>
            </dirset>
        </classpath>

        <hbm2ddl outputfilename="schemaexport.sql" format="true" export="false" drop="true" />
    </hibernatetool>
</target>

Error message (ant -v):

    Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: /home/joe/workspace/bento/ant-generate-ddl.xml
parsing buildfile /home/joe/workspace/bento/ant-generate-ddl.xml with URI = file:/home/joe/workspace/bento/ant-generate-ddl.xml
Project base dir set to: /home/joe/workspace/bento
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.

BUILD FAILED
/home/joe/workspace/bento/ant-generate-ddl.xml:12: Only antlib URIs can be located from the URI alone,not the URI 
    at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:216)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:140)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.parseBuildFile(InternalAntRunner.java:191)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:400)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

Total time: 195 milliseconds

I'm trying to run hibernate tools in an ant build to generate ddl from my JPA annotations. Ant dies on the taskdef tag. I've tried with ant 1.7, 1.6.5, and 1.6 to no avail. I've tried both in eclipse and outside. I've tried including all the hbn jars in the hibernate-tools path and not. Note that I based my build file on this post:

Hibernate JPA to DDL command line tools

I'm running eclipse 3.4 with WTP 3.0.1 and MyEclipse 7.1 on Ubuntu 8.

Build.xml:

<project name="generateddl" default="generate-ddl">

<path id="hibernate-tools">
    <pathelement location="../libraries/hibernate-tools/hibernate-tools.jar" />
    <pathelement location="../libraries/hibernate-tools/bsh-2.0b1.jar" />
    <pathelement location="../libraries/hibernate-tools/freemarker.jar" />
    <pathelement location="../libraries/jtds/jtds-1.2.2.jar" />
    <pathelement location="../libraries/hibernate-tools/jtidy-r8-20060801.jar" />

</path>

<taskdef classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernate-tools"/>

<target name="generate-ddl" description="Export schema to DDL file"> 
<!-- compile model classes before running hibernatetool -->

    <!-- task definition; project.class.path contains all necessary libs 
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path" />
    -->

    <hibernatetool destdir="sql"> 

        <!-- check that directory exists -->
        <jpaconfiguration persistenceunit="default" />

        <classpath>

            <dirset dir="WebRoot/WEB-INF/classes">
                <include name="**/*"/>
            </dirset>
        </classpath>

        <hbm2ddl outputfilename="schemaexport.sql" format="true" export="false" drop="true" />
    </hibernatetool>
</target>

Error message (ant -v):

    Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: /home/joe/workspace/bento/ant-generate-ddl.xml
parsing buildfile /home/joe/workspace/bento/ant-generate-ddl.xml with URI = file:/home/joe/workspace/bento/ant-generate-ddl.xml
Project base dir set to: /home/joe/workspace/bento
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.

BUILD FAILED
/home/joe/workspace/bento/ant-generate-ddl.xml:12: Only antlib URIs can be located from the URI alone,not the URI 
    at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:216)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:140)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.parseBuildFile(InternalAntRunner.java:191)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:400)
    at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

Total time: 195 milliseconds

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澜川若宁 2024-07-24 07:16:54

根据 typedef 任务文档(其中taskdef 任务 是一种形式)如果您未指定“文件或资源类型属性”,则需要 name 属性。

我不确定解决这个问题是否可以解决您的问题,但如果您可以消除潜在原因,那就太好了。

According to the typedef task documentation (of which the taskdef task is a form of) the name attribute is required if you haven't specified "the file or resource type attributes".

I'm not sure if fixing that up will sort your problem but it would be good if you could eliminate that from being a potential cause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文