Using xjc's -enableIntrospection with jaxws-maven-plugin
Having run into http://java.net/jira/browse/JAXB-131, we are trying to adopt the cure provided in its comments, which is to supply -enableIntrospection on xjc's command line.
However, when I do:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>allservice</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<xjcArgs><xjcArg>-enableIntrospection</xjcArg></xjcArgs>
<extension>true</extension>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<bindingDirectory>src/main/resources/bindings</bindingDirectory>
<target>2.0</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
The maven build fails with:
[DEBUG] The binding Directory is C:\Source\workspace\TheProject\src\main\resources\bindings
[DEBUG] jaxws:wsimport args: [-s, C:\Source\workspace\TheProject\target\jaxws\wsimport\java, -d, C:\Source\workspace\TheProject\target\classes, -target, 2.0, -extension, -Xnocompile, -B-enableIntrospection, -b, C:\Source\workspace\TheProject\src\main\resources\bin开发者_开发问答dings\servicebindings.xml]
[INFO] jaxws:wsimport args: [-s, C:\Source\workspace\TheProject\target\jaxws\wsimport\java, -d, C:\Source\workspace\TheProject\target\classes, -target, 2.0, -extension, -Xnocompile, -B-enableIntrospection, -b, C:\Source\workspace\TheProject\src\main\resources\bindings\servicebindings.xml, C:\Source\workspace\TheProject\src\main\webapp\WEB-INF\wsdl\CaseService.wsdl]
no such JAXB option: -enableIntrospection
How can I use xjc's -enableIntrospection with jaxws-maven-plugin? If I can't, what alternatives exist to customize jaxws's code generation so that the getter for a Boolean
property is called getFoo()
(correct) rather than isFoo()
(which violates the Java Beans spec).
Add getters for Booleans to the JAX-WS generated artifacts, instead of using the enableIntrospection option and the Java endorsed override mechanism.
Only JAX-WS RI 2.1.13 supports the option enableIntrospection. But JavaSE6 1.6.0_65 ships with JAVA-WS RI 2.1.6. One way to fix this is to use the Java endorsed override mechanism, to copy jaxws-api.jar and jaxb-api.jar into JRE/JDK endorsed directory.
Another way is not to use the enableIntrospection option, but to add getters for Booleans to the JAX-WS generated artifacts. These getters can be added with the replacer maven plugin.
Maven replacer plugin to add a get method:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.basedir}</basedir>
<includes>
<include>src/main/java/lu/etat/cie/rn/rpp/ws/**/*.java</include>
</includes>
<token>public Boolean is(.*)\(\)(\s*\{\s*.+\s*\})</token>
<value>public Boolean is$1\(\)$2
public Boolean get$1\(\)$2</value>
</configuration>
</plugin>
Replaces:
public Boolean isProperty() {
return property;
}
With:
public Boolean isProperty() {
return property;
}
public Boolean getProperty() {
return property;
}
It appears that the jaxws-maven-plugin uses the xjc from the installed JDK. The newest Oracle JDK still contains a version of XJC before support for -enableIntrospection was added.
I next looked into using a JAXB-Plugin. It turns out that the jaxws-maven-plugin offers no easy way to append to the classpath of XJC, which is required to load JAXB-Plugins.
Replacing the jaxws-maven-plugin was not possible for political reasons (something like "jaxws is the standard, only standard libraries may be used").
I have therefore fallen back to writing a maven plugin that reads the source code after generation, does
content.replace("public Boolean is", "public Boolean get");
and writes the source file back to disk. That has also allowed me to inject definitions of equals()
and hashCode()
that rely on the naming convention for business keys in the API I am consuming.
You can try
<enableIntrospection>true</enableIntrospection>
in <configuration>
also I can find:
<args>
<arg>-enableIntrospection</arg>
</args>
in
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
精彩评论