Search code examples
javajaxb2maven-jaxb2-plugin

Running custom JAXB2 plugins using Maven JAXB 2.x Plugin


I would like to generate JAXB Java classes using the Maven JAXB 2.x plugin http://static.highsource.org/mjiip/maven-jaxb2-plugin/generate-mojo.html

To declare the custom JAXB plugins I would execute during the generate process, I used the "args" element like below:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.7.4</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xinheritance</arg>
            <arg>-XtoString</arg>
        </args>
        ...
    </configuration>
    ...
</plugin>

The issue is that the maven generate process is failing with the following error:

Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.7.4:generate (default) on project was: Error parsing the command line [[Ljava.lang.String;@1ad4a1ae]

Any idea on how to specify the args values?

Thanks


Solution

  • Here's a sample plugin config:

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <configuration>
            <extension>true</extension>
            <args>
                <arg>-XtoString</arg>
                <arg>-Xequals</arg>
                <arg>-Xinheritance</arg>
                <arg>-Xsetters</arg>
            </args>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.2</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>
    

    I think you were only missing the plugins/plugin definition.