Question

I have determined that two JAXB plugins for Maven 2 exist, with some different configurations.

The one is from Sun: http://jaxb.dev.java.net/jaxb-maven2-plugin/, the other from Mojohaus: http://mojohaus.org/jaxb2-maven-plugin/

Which of these two plugins can be recommended?


Thanks Matt. On my little research project, I found that there's quite another plugin comming from the sunners:

<groupId>com.sun.tools.xjc.maven2</groupId>  
<artifactId>maven-jaxb-plugin</artifactId>  

and that one:

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>

and still the one from Codehouse.

Was it helpful?

Solution

Let's summarize. We have:

  1. the maven-jaxb2-plugin (https://github.com/highsource/maven-jaxb2-plugin)
  2. the maven-jaxb-plugin (https://jaxb.dev.java.net/jaxb-maven2-plugin/)
  3. the jaxb2-maven-plugin (https://github.com/mojohaus/jaxb2-maven-plugin)

Based on the comments of this thread, I've always used the maven-jaxb2-plugin (i.e. plugin #1):

Concerning the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin versus com.sun.tools.xjc.maven2:maven-jaxb-plugin, from my point of view it's definitely the first one (http://maven-jaxb2-plugin.java.net/).

This plugin has much more features than com.sun.tools.xjc.maven2:maven-jaxb-plugin, the development is active. Finally, I'm one of the authors :) and I'd say we keep in touch with JAXB developers and users and react to the latests features/requests.

And indeed, the plugin #2 isn't very active (dead?). And because I've always been happy with #1, I've never used plugin #3 so can't really say anything about it. Just in case, here is a working configuration for plugin #1:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <inherited>true</inherited>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

OTHER TIPS

I have recently tried the three plug-ins mentioned above (included here as well):

  1. the maven-jaxb2-plugin (http://maven-jaxb2-plugin.java.net/)
  2. the maven-jaxb-plugin (https://jaxb.dev.java.net/jaxb-maven2-plugin/)
  3. the jaxb2-maven-plugin (http://mojo.codehaus.org/jaxb2-maven-plugin/)

I ended up using a fourth option: The CXF XJC Maven Plugin http://cxf.apache.org/cxf-xjc-plugin.html

If I am missing something I would like to know, but the configuration seemed more straightforward for what I was trying to do and more easily allowed me to to deal with duplicate class generation within the same namespace -- similar to this question: Is there a way to deal with duplicate element definitions across multiple .xsd files in JAXB?.

I now have granular control over each incoming XSD and corresponding java package; here is a sample configuration close to the one I am using.

 <plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <version>2.3.0</version>
    <configuration>
        <extensions>
            <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
        </extensions>
    </configuration>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xsdtojava</goal>
            </goals>
            <configuration>
                <sourceRoot>${basedir}/target/generated-sources/src/main/java</sourceRoot>
                <xsdOptions>
                    <xsdOption>
                        <xsd>src/main/resources/schema/commands.xsd</xsd> <!--shares a common.xsd file causing the conflicts-->
                        <packagename>com.foo.bar.commands</packagename>
                    </xsdOption>
                    <xsdOption>
                        <xsd>src/main/resources/schema/responses.xsd</xsd>
                        <packagename>com.foo.bar.responses</packagename>
                    </xsdOption>
                </xsdOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

I am the author of maven-jaxb2-plugin.

The maven-jaxb2-plugin currently uses JAXB 2.1. In the next versions we'll also provide JAXB 2.0 and JAXB 2.2 versions.

As for "which plugin is better" discussion, check the features, decide yourself. Let me know if you miss some functionality.

  • maven-jaxb2-plugin uses the JAXB reference implementation by Oracle/Sun
  • cxf and jaxb2-maven-plugin use Apache Xerces

On a slight tangent: there was a problem with use of maven-jaxb2-plugin with Eclipse Indigo that I posted here. A fix (extension) has recently become available.

This is not meant to disagree, at all, with the recommendation of maven-jaxb2-plugin over maven2-jaxb-plugin. I don't know, but I expect that maven2-jaxb-plugin has the same problem, probably unresolved.

I would guess that one is for the original JAXB specification and the codehaus one is for the JAXB 2.1 specification (and if the dev.java.net would load some time this century, I'd be able to say for sure).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top