Sharing my experience about migrating from
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
to
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
we have used the original plugin to generate sources out of WSDL files. There was a request to use Java 11 instead of Java 8 and after the change the original plugin generated warnings.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/D:/mr/org/glassfish/jaxb/jaxb-runtime/2.3.0/jaxb-runtime-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Since this problem is still reported as a bug in maven-jaxb2-plugin and there was no update on this plugin since 2018, we have decided to move the mojo plugin.
Here is how the original execution looked like:
<execution>
<id>uniqa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemaDirectory>src/main/resources/brokeredinsurance/uniqa/out</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<generatePackage>at.porschebank.brokeredinsurance.uniqa.out</generatePackage>
<generateDirectory>
${project.build.directory}/generated-sources/brokeredinsurance/uniqa/out
</generateDirectory>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.5</version>
</plugin>
</plugins>
<bindingDirectory>src/main/resources</bindingDirectory>
</configuration>
</execution>
and after migrating the new plugin
<execution>
<id>uniqa</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/brokeredinsurance/uniqa/out</source>
</sources>
<packageName>at.porschebank.brokeredinsurance.uniqa.out</packageName>
<outputDirectory>
${project.build.directory}/generated-sources/brokeredinsurance/uniqa/out
</outputDirectory>
<xjbSources>
<xjbSource>src/main/resources/jaxb-bindings.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
In the new plugin we have different tags, but mapping them is quite obviously from the codes above.
I had to change the goal
in the new execution since the new plugin uses different. So it went from generate
to xjc
. See the plugin documentation here What is the JAXB2 Maven Plugin? and about xjc here jaxb2:testXjc
We did not use anymore the <schemaInclude>
tag because our directory contained only wsdl files.Also we removed the extra plugin definition, because it was not needed with the new plugin.
Summary
Moving to the new plugin was quite easy, but it needed a little time to figure it out the mapping of the tags.
However, I faced with one problem during the migration, because we have everything in the src/main/resources
folder where we have the xjb file in the root.
The documentation says <xjbSource>
can contain directories as well, what is valid, but when I defined only the folder I got the following error:
org.xml.sax.SAXParseException: not an external binding file. The root element must be {http://java.sun.com/xml/ns/jaxb}bindings but it is {http://schemas.xmlsoap.org/wsdl/}definitions
This is obvious, because we have the wsdl files in the same folder (in sub folders) as well and the plugin travers through the entire content during the initialization and it found first the wsdl file.
So, in my case, the solution was to define the path to the file. After this it generated the classes immediatelly.