Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get JAXB2 to emit CamelCase bindings?

I'm generating Java classes from a WSDL using the jaxws-maven-plugin's wsimport goal. Out of the box, this generates hideous classes and methods from the XML schema; e.g., a class called MYOBJECT from an XML element named MY_OBJECT.

I've found that I can customize my JAXB2 bindings with an external file; this would be acceptable for a small number of classes and methods, but the overhead of manually naming everything in this case is undesirable.

Some searching uncovers references to an XJC CamelCase Always plugin, but this appears to be unmaintained and most links are 404s. Not willing to give up, I did find a camelcase-always Maven artifact which appears to provide this functionality, but I'm not sure how to configure this so that jaxws-maven-plugin uses it.

How can I get CamelCase bindings without specifying them all manually?

like image 852
Lyle Avatar asked Jan 18 '12 19:01

Lyle


1 Answers

I didn't find examples of how to do this with jaxws-maven-plugin, but I did find examples using the maven-jaxb2-plugin.

First, you need a repository added to your POM:

<repository>
    <id>releases</id>
    <name>Releases</name>
    <url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>

Note the plugin declaration and arguments added to the maven-jaxb2-plugin execution.

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.0</version>
    <executions>
        <execution>
            <id>jaxb-generate</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generatePackage>YOUR.PACKAGE.HERE</generatePackage>
        <args>
            <arg>-camelcase-always</arg>
        </args>
        <bindingDirectory>src/main/binding</bindingDirectory>
        <schemas>
            <schema>
                <url>http://YOUR.WSDL.HERE</url>
            </schema>
        </schemas>
        <extension>true</extension>
        <plugins>
            <plugin>
                <groupId>org.andromda.thirdparty.jaxb2_commons</groupId>
                <artifactId>camelcase-always</artifactId>
                <version>1.0</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

See the docs for more details.

like image 97
Lyle Avatar answered Oct 04 '22 23:10

Lyle