Two Minute Introduction

Setting up xdoclet 2

It's really not that difficult to set up XDoclet2, but some of the dependencies (like Jelly) can give some very unhelpful error messages if they are not properly fed with a healthy lunch of the proper dependencies.

  • First, add dependencies to your project.xml. The best place to look for the current dependencies is in the project.xml from XDoclet Plugins. You only need dependencies down to the line that reads "<!-- Build/Test time only -->". If you are using Ant, include each of the JARs listed in this document in the build classpath.
  • Now, set up the instructions in your build for Maven:
    XDoclet2 Invocation with Maven
    <goal name="xdoclet">
      <taskdef name="xdoclet" classname="org.xdoclet.ant.XDocletTask" 
                              classpathref="maven.dependency.classpath" />
      <xdoclet>
        <fileset dir="${pom.build.sourceDirectory}">
          <include name="**/*.java"/>
        </fileset>
        <component classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin" 
                   destdir="${maven.build.dir}/xdoclet/hibernatedoclet"/>
        <!-- add more plugins here! -->
      </xdoclet>
    </goal>
    
    <preGoal name="java:compile">
      <!-- Add paths containing your generated sources to java:compile source set. -->
      <path id="maven.compile.src.set">
        <pathelement location="src/java"/>
        <pathelement location="target/src"/>
        <pathelement location="${maven.build.dir}/xdoclet/hibernatedoclet"/>
      </path>
      <attainGoal name="xdoclet"/>
    </preGoal>
  • ...or Ant:
    XDoclet2 Invocation with Ant
    <project name="xdoclet-sample" default="xdoclet">
    
       <property file="build.properties"/>
       <property name="xdoclet.lib.dir" value="${user.home}/.maven/repository"/>
    
       <target name="xdoclet">
           <mkdir dir="${basedir}/target/xdoclet/persistence"/>
           <path id="xdoclet.task.classpath">
               <!-- Add the xdoclet2 plugins jar here -->
               <pathelement location="${xdoclet.lib.dir}/xdoclet-plugins/jars/your-plugin.jar"/>
    
               <!-- xdoclet2 runtime dependencies -->
               <pathelement location="${xdoclet.lib.dir}/xdoclet/jars/xdoclet2-SNAPSHOT.jar"/>
               <pathelement location="${xdoclet.lib.dir}/generama/jars/generama-SNAPSHOT.jar"/>
               <pathelement location="${xdoclet.lib.dir}/picocontainer/jars/picocontainer-1.0.jar"/>
               <pathelement location="${xdoclet.lib.dir}/nanocontainer/jars/nanocontainer-1.0-beta-1.jar"/>
               <pathelement location="${xdoclet.lib.dir}/nanocontainer/jars/nanocontainer-ant-1.0-beta-1.jar"/>
               <pathelement location="${xdoclet.lib.dir}/qdox/jars/qdox-1.6-SNAPSHOT.jar"/>
               <pathelement location="${xdoclet.lib.dir}/velocity/jars/velocity-1.4.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-collections/jars/commons-collections-2.1.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-jelly/jars/commons-jelly-1.0-beta-4-SNAPSHOT.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-jelly/jars/commons-jelly-tags-define-20030211.142932.jar"/>
               <pathelement location="${xdoclet.lib.dir}/log4j/jars/log4j-1.2.8.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-logging/jars/commons-logging-1.0.4.jar"/>
               <pathelement location="${xdoclet.lib.dir}/dom4j/jars/dom4j-1.4.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-beanutils/jars/commons-beanutils-1.6.1.jar"/>
               <pathelement location="${xdoclet.lib.dir}/commons-jexl/jars/commons-jexl-1.0-beta-2.jar"/>
           </path>
    
           <taskdef
               name="xdoclet"
               classname="org.xdoclet.ant.XDocletTask"
               classpathref="xdoclet.task.classpath"
               />
    
           <xdoclet>
               <!-- defines the file handled by xdoclet2 -->
               <fileset dir="src/java">
                   <include name="**/*.java"/>
               </fileset>
    
               <!-- defines the processing of a plugin -->
               <component
                 classname="com.company.xdoclet.YourPlugin"
                 destdir="${basedir}/target/xdoclet/"
                 />
           </xdoclet>
       </target>
    
    </project>
  • Launch your build and see what happens!

If you have questions about these instructions, please join the user mailing list and ask them there.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 23

    Timothy Twelves says:

    I could not find any good examples with EjbDoclet, Maven2 and the Weblogic plugi...

    I could not find any good examples with EjbDoclet, Maven2 and the Weblogic plugin.

    Customise accordingly.

    XDoclet2 Invocation with Maven 2 and EJB Doclet
    <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.xdoclet</groupId>
            <artifactId>maven2-xdoclet2-plugin</artifactId>
            <version>2.0.6</version>
            <executions>
              <execution>
                <phase>generate-sources</phase>
                <goals>
                  <goal>xdoclet</goal>
                </goals>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>xdoclet-plugins</groupId>
                <artifactId>xdoclet-plugin-ejb</artifactId>
                <version>1.0.4</version>
              </dependency>
              <dependency>
                <groupId>xdoclet-plugins</groupId>
                <artifactId>xdoclet-plugin-weblogic</artifactId>
                <version>1.0.4</version>
              </dependency>
              <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.14</version>
              </dependency>
            </dependencies>
            <configuration>
              <configs>
                <config>
                  <components>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.EjbConfig</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.interfaces.RemoteHomeInterfacePlugin</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.interfaces.RemoteInterfacePlugin</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.interfaces.LocalHomeInterfacePlugin</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.interfaces.LocalInterfacePlugin</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.ejb.descriptor.EjbJarXmlPlugin</classname>
                    </component>
                    <component>
                      <classname>org.xdoclet.plugin.weblogic.ejb.descriptor.WeblogicEjbJarXmlPlugin</classname>
                    </component>
                  </components>
                  <params>
                    <!-- foo.baa.sessions.MyServiceBean  becomes  foo.bar.interfaces.MyService -->
                    <packageregex>sessions</packageregex>
                    <packagereplace>interfaces</packagereplace>
                    <validate>false</validate>
                  </params>
                </config>
              </configs>
            </configuration>
          </plugin>
        </plugins>
      </build>

    When migrating new projects to XDoclet two it may be important to get XDoclet 1 working. Seen below is what is required to get XDoclet 1 going. Note the different task structure. The following link may be critical in showing how its done http://www.mail-archive.com/xdoclet-user@lists.sourceforge.net/msg11262.html and the following two examples are extracts.

    XDoclet 1 Invocation with Maven 2 and EJB Doclet
    <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xdoclet-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>generate-sources</phase>
                <goals>
                  <goal>xdoclet</goal>
                </goals>
                <configuration>
                  <generatedSourcesDirectory>${project.build.directory}/xdoclet</generatedSourcesDirectory>
                  <tasks>
                    <ejbdoclet
                        excludedtags="@version,@author"
                        addedtags="@xdoclet-generated at ${NOW_UK},@author XDoclet"
                        verbose="false" ejbSpec="2.1"
                        destDir="${project.build.directory}/xdoclet"
                        force="false">
                      <fileset dir="${project.build.sourceDirectory}">
                        <include name="**/*Bean.java"/>
                        <include name="**/*MDB.java"/>
                      </fileset>
                      <remoteinterface/>
                      <localinterface/>
                      <homeinterface/>
                      <localhomeinterface/>
                      <dataobject/>
                      <entitypk/>
                      <deploymentdescriptor destDir="${project.build.outputDirectory}/META-INF"/>
                    </ejbdoclet>
                    <ejbdoclet
                        excludedtags="@version,@author"
                        addedtags="@xdoclet-generated at ${NOW_UK},@author XDoclet"
                        verbose="false"
                        ejbSpec="2.0"
                        destDir="${project.build.directory}/xdoclet"
                        force="false">
                      <fileset dir="${project.build.sourceDirectory}">
                        <include name="**/*Bean.java"/>
                        <include name="**/*MDB.java"/>
                      </fileset>
                      <weblogic
                          datasource="jdbc/TxTopUpDB"
                          createtables="Disabled"
                          databaseType="ORACLE"
                          destDir="${project.build.outputDirectory}/META-INF"
                          validateXML="true"
                          version="8.1"/>
                    </ejbdoclet>
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    XDoclet 1 Invocation with Maven 2 and Web Doclet
    <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xdoclet-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>generate-sources</phase>
                <goals>
                  <goal>xdoclet</goal>
                </goals>
                <configuration>
                  <tasks>
                    <webdoclet destdir="${project.build.directory}/generated-sources/xdoclet/META-INF">
                      <fileset dir="${project.build.sourceDirectory}">
                        <include name="**/*.java"/>
                      </fileset>
                      <deploymentdescriptor servletspec="2.3"/>
                    </webdoclet>
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>

    To get this working working cleanly with Artifactory may be slightly difficult since it only supports Maven 2 repositories. Various Maven 1 resources are not available and may have to be added to your local repository. You will need to configure the following in Artifactory:

    Required Artifactory Repositories
    http://repo1.maven.org/maven2/
    http://mirrors.ibiblio.org/pub/mirrors/maven2/
    http://repository.codehaus.org/
    http://download.java.net/maven/2/
    http://www.jfrog.org/artifactory/plugins-releases@repo
    http://repository.jboss.com/maven2/