How can I get JAXB2 to emit CamelCase bindings?

I am generating Java classes from WSDL using jaxws-maven-plugin wsimport . Out of the box, this generates disgusting classes and methods from an XML schema; for example, a class called MYOBJECT from an XML element named MY_OBJECT.

I found that I can configure 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 searches reveal links to the XJC CamelCase Always plugin, but that doesn't seem to be supported, and most links are 404. Not wanting to give up, I found camelcase-always a Maven artifact that seems to provide this feature, but I'm not sure how to configure this so that uses jaxws-maven-plugin.

How can I get CamelCase bindings without specifying them manually?

+6
source share
2 answers

I did not find examples of how to do this using jaxws-maven-plugin , but I found examples using maven-jaxb2-plugin .

First you need to add the repository 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 docs for more details.

+5
source

May be useful for users of Apache CXF and cxf-xjc-plugin.

 <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-xjc-plugin</artifactId> <version>3.1.0</version> <configuration> <extensions> <extension>org.andromda.thirdparty.jaxb2_commons:camelcase-always:1.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/cxf</sourceRoot> <xsdOptions> <xsdOption> <xsd>YOUR.XSD.HERE</xsd> <packagename>YOUR.PACKAGE.HERE</packagename> <extensionArgs> <extensionArg>-camelcase-always</extensionArg> </extensionArgs> <extension>true</extension> </xsdOption> </xsdOptions> </configuration> </execution> </executions> </plugin> 
0
source

Source: https://habr.com/ru/post/906333/


All Articles