0

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)
lalit
  • 1,485
  • 2
  • 17
  • 32
  • Why are you using XDoclet? XDoclet was an alternative to XML configuration when Java annotations didn't exist. Now Java annotations exist, and Hibernate can be configured using them. – JB Nizet Oct 07 '11 at 10:29
  • I am planning to go to Java annotation way but migrating the application in phases. In the first step want to migrate from ant to maven without touching the code so that's the reason for working the xdoclet way to begin with. – lalit Oct 07 '11 at 13:24

1 Answers1

1

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.

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • By pulling the hibernate jars, it seems to have solved the problem. Thanks for the same. Now I am seeing that it is not able to handle generics in the Java file. Is there a way to make the pluin to handle generics also. – lalit Oct 07 '11 at 13:42
  • No. This is the problem with using out of date technology. As JB Nizet already pointed out XDoclet was developed prior to Java 5 as a means to approximate annotations before they existed as a Java language construct. Unfortunately good stuff like generics also did not exist as a Java language construct at that time – Steve Ebersole Jun 12 '12 at 13:30