Migration from maven-jaxb2-plugin 0.14.0 to jaxb2-maven-plugin 2.5.0
Asked Answered
C

1

9

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.

Come answered 11/2, 2021 at 8:35 Comment(1)
Can you share your jaxb-bindings.xjb file for reference? Do we need to replace the xmlns:jaxb="java.sun.com/xml/ns/jaxb" with the jakarta urlsOctad
E
1

I know this question is a bit old but the original plugin has been updated this year with many changes :

  • some repositories related to maven-jaxb2-plugin have been merged into the main repository, renamed jaxb-tools (jaxb2-basics is one of them)
  • versions have been aligned in order to make it easier to target the good version of jaxb-plugins with the version of the maven plugin
  • the plugin is know tested against JDK8/JDK11/JDK17 and also JDK21 (all LTS java version)
  • we also do the upgrade to support Jakarta EE9 (JAXB3) and EE10 (JAXB4), with JDK11 baseline for the latest
  • many bugs have been fixed, and we do actively support the JAXB2 / JAXB4 versions of the plugin

If you're interested, you can read and follow the migration guide since we did some groupId moves (all is now published under org.jvnet.jaxb groupId) and did some artifactId renaming.

For your configuration, if still under JAXB2, you could move to

<plugin>
   <groupId>org.jvnet.jaxb</groupId>
   <artifactId>jaxb-maven-plugin</artifactId>
   <version>2.0.9</version>

and in configuration section, change the jaxb2-basics ref to the following

<execution>
    <configuration>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>2.0.9</version>
            </plugin>
        </plugins>
Enfeeble answered 16/11, 2023 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.