使用 Xdoclet 在 hibernate 中生成 hbm 文件的 Maven ant 插件存在问题

发布于 2024-12-08 10:04:35 字数 4925 浏览 1 评论 0原文

我正在尝试使用 ant 任务和 Maven 生成 hbm 文件,但是它遇到了与类路径相关的问题。 (我这样做是为了将项目从ant迁移到maven,并且不想改变hibernate在第一步中的工作方式)。如果有人知道更好的方法来处理这个问题,那也会有帮助。我的 pom.xml 看起来像

            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-nodeps</artifactId>
                    <version>1.8.1</version>
                </dependency>
                <dependency>
                    <groupId>xdoclet</groupId>
                    <artifactId>xdoclet-hibernate-module</artifactId>
                    <version>1.2.3</version>
                </dependency>
                <dependency>
                    <groupId>xjavadoc</groupId>
                    <artifactId>xjavadoc</artifactId>
                    <version>1.1</version>
                </dependency>
                <dependency>
                    <groupId>xdoclet</groupId>
                    <artifactId>xdoclet-xdoclet-module</artifactId>
                    <version>1.2.3</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.xdoclet</groupId>
                    <artifactId>xdoclet</artifactId>
                    <version>2.0.7</version>
                </dependency>
                <dependency>
                    <groupId>commons-collections</groupId>
                    <artifactId>commons-collections</artifactId>
                    <version>20040616</version>
                </dependency>
                <dependency>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                    <version>1.1.1</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase> generate-sources</phase>
                    <configuration>
                        <target name="generate-hibernate" unless="hibernatedoclet.unnecessary">
                            <echo level="info">generating hibernate files</echo>
                            <taskdef name="hibernatedoclet"
                                classname="xdoclet.modules.hibernate.HibernateDocletTask"
                                classpathref="maven.plugin.classpath" />
                            <hibernatedoclet destdir="${project.build.directory}"
                                force="ture" verbose="true">
                                <fileset id="hbm" dir="${basedir}/src/main/java">
                                    <include name="**/model/*.java" />
                                </fileset>
                                <hibernate version="3.0" />
                            </hibernatedoclet>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

我得到的例外是

   Can't create a hibernate element under hibernatedoclet. Make sure the jar file containing    the corresponding subtask class is on the classpath specified in the <taskdef> that defined {2}.
    at xdoclet.DocletTask.createDynamicElement(DocletTask.java:343)
    at org.apache.tools.ant.IntrospectionHelper.createDynamicElement(IntrospectionHelper.java:57
    at org.apache.tools.ant.IntrospectionHelper.getNestedCreator(IntrospectionHelper.java:542)
    at org.apache.tools.ant.IntrospectionHelper.getElementCreator(IntrospectionHelper.java:637)
    at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:552)
    at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:349)
    at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:201)
    at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
    at org.apache.tools.ant.Task.perform(Task.java:347)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
    at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)

I am trying to generate hbm files using ant task with maven, however it's running into issues related to classpath. (I am doing this to migrate the project from ant to maven and do not want to change the way hibernate works in the first step). If someone knows a better way to handle this, that would also be helpful. My pom.xml looks like

            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-nodeps</artifactId>
                    <version>1.8.1</version>
                </dependency>
                <dependency>
                    <groupId>xdoclet</groupId>
                    <artifactId>xdoclet-hibernate-module</artifactId>
                    <version>1.2.3</version>
                </dependency>
                <dependency>
                    <groupId>xjavadoc</groupId>
                    <artifactId>xjavadoc</artifactId>
                    <version>1.1</version>
                </dependency>
                <dependency>
                    <groupId>xdoclet</groupId>
                    <artifactId>xdoclet-xdoclet-module</artifactId>
                    <version>1.2.3</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.xdoclet</groupId>
                    <artifactId>xdoclet</artifactId>
                    <version>2.0.7</version>
                </dependency>
                <dependency>
                    <groupId>commons-collections</groupId>
                    <artifactId>commons-collections</artifactId>
                    <version>20040616</version>
                </dependency>
                <dependency>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                    <version>1.1.1</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase> generate-sources</phase>
                    <configuration>
                        <target name="generate-hibernate" unless="hibernatedoclet.unnecessary">
                            <echo level="info">generating hibernate files</echo>
                            <taskdef name="hibernatedoclet"
                                classname="xdoclet.modules.hibernate.HibernateDocletTask"
                                classpathref="maven.plugin.classpath" />
                            <hibernatedoclet destdir="${project.build.directory}"
                                force="ture" verbose="true">
                                <fileset id="hbm" dir="${basedir}/src/main/java">
                                    <include name="**/model/*.java" />
                                </fileset>
                                <hibernate version="3.0" />
                            </hibernatedoclet>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

The exception that I am getting is

   Can't create a hibernate element under hibernatedoclet. Make sure the jar file containing    the corresponding subtask class is on the classpath specified in the <taskdef> that defined {2}.
    at xdoclet.DocletTask.createDynamicElement(DocletTask.java:343)
    at org.apache.tools.ant.IntrospectionHelper.createDynamicElement(IntrospectionHelper.java:57
    at org.apache.tools.ant.IntrospectionHelper.getNestedCreator(IntrospectionHelper.java:542)
    at org.apache.tools.ant.IntrospectionHelper.getElementCreator(IntrospectionHelper.java:637)
    at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:552)
    at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:349)
    at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:201)
    at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
    at org.apache.tools.ant.Task.perform(Task.java:347)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1366)
    at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:270)

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

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

发布评论

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

评论(1

踏月而来 2024-12-15 10:04:35

正如错误所说

无法在 hibernatedoclet 下创建 hibernate 元素

我想您需要将 hibernate 添加到您的 maven ant 插件依赖项中。

As the error says

Can't create a hibernate element under hibernatedoclet

I guess you need to add hibernate to your maven ant plugin dependency.

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