I am using maven-jaxb2-plugin to generate java classes from a service wsdl I imported into the project.
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration> <schemaDirectory>src/main/resources</schemaDirectory>
<schemaLanguage>WSDL</schemaLanguage>
<schemaIncludes>
<schemaInclude>blabla.wsdl</schemaInclude>
</schemaIncludes>
<bindingIncludes>
<bindingInclude>bindings.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
This worked fine, and for each object, builder functions were generated. So basic .withParameter(Param param) functions, which set the value, and returns itself.
Unfortunately, an XmlRootElement annotation was not added to the main request en response objects. I learned you could add this by adding the plugin jasb2-basics-annotate, and add the argument -Xannotate to the pom.
The resultig pom is:
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin> <groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.0</version>
</plugin>
</plugins>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaLanguage>WSDL</schemaLanguage>
<schemaIncludes>
<schemaInclude>blabla.wsdl</schemaInclude>
</schemaIncludes>
<bindingIncludes>
<bindingInclude>bindings.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
This works fine for the @XmlRootElement annotations that I needed. Unfortunately though, the builder functions are no longer generated. Now the objects only have getters and setters.
Does anyone know what causes this, and if there is a way to get it to generate these functions again?
You can add another plugin just after jaxb2-basics-annotate to generate builders, namely:
<plugin>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>2.1.8</version>
</plugin>
You must also include the following arguments:
<args>
<arg>-Xannotate</arg>
<arg>-Xfluent-api</arg>
</args>
Please also check that the fluent-api plugin was not already added in another part of the configuration (probably pluginManagement in one of the pom's hierarchical parents) as the problem may be that you've just overriden the args from pluginManagement in plugins and that's why it stopped working.