3

When trying to build our project from within Eclipse I keep getting the following error:

Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java failed: A required class was missing while executing org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java: javax/xml/bind/annotation/adapters/HexBinaryAdapter

The reason for that is that - while we still compile for a Java-8 target environment - the tool chain (i.e. Eclipse, M2E (Eclipe's Maven-plugin), Maven, and CXF) is executed using Java-11. In Java 9+ javax/xml/bind is not part of the rt.jar anymore, hence the class is missing when the plugin tries to start up. Elsewhere I found that one can enable it by specifying an "--add-modules java.xml.bind" JVM option.

I tried adding that option to the MAVEN_OPTS environment variable but that is apparently ignored when M2E starts up Maven (and with it the CXF plugin) in a separate VM.

Next I tried to specify that option in the plugin's configuration in the pom.xml like so:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <fork>true</fork>
                            <additionalJvmArgs>--add-modules java.xml.bind</additionalJvmArgs>
                            ...
                        </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        ...

... but that also didn't fly. :-(

Any idea anyone, how and where one can specify that option or how I can make the former standard javax-classes available to a Maven-plugin running under Java 9+ (when executed from Eclipse M2E) ?

Just in case: this is NOT an Eclipse or M2E issues! Even when I start Maven on the command line using Java 9+ I get:

...
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java (generate-sources) on project my_project: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java failed: A required class was missing while executing org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java: javax/xml/bind/annotation/adapters/HexBinaryAdapter
mmo
  • 3,897
  • 11
  • 42
  • 63
  • Check [this answer](https://stackoverflow.com/a/43574427/2834978) , seems `--add-modules` does not work with java 11 out of the box. – LMC Oct 11 '21 at 16:05
  • Can you use a newer version of the plug-in? 3.2.0 was released around the same time as Java 9, long before certain APIs like JAXB were outright removed from Java 11. – nitind Oct 11 '21 at 17:52
  • 1
    @LMC thanks for the pointer. I went for the suggested "proper long-term solution" and added `javax.xml.bind:jaxb-api` and `com.sun.xml.bind:jaxb-impl` as dependencies for the cxf-codegen-plugin. This indeed changed things. No more missing class, now, but some some odd `Illegal reflective access by lombok.javac.apt.LombokProcessor...` error. :-( No idea, yet, whether that's related to the above or a completely different issue now. We'll see... – mmo Oct 11 '21 at 19:34
  • Well, I don't like Lombok for that kind of problems. – LMC Oct 11 '21 at 19:47
  • 1
    OK - upgrading to Lombok v1.18.16 solved that issue. Now I get a compile error due to missing class `javax.annotation.Generated` and that's now at compile time of the previously generated code, so the cxf-plugin seems to have completed its job. Guess this "game" will continue for a while but the initial issue with the missing `javax/xml/bind/annotation/adapters/HexBinaryAdapter` during plugin execution seems indeed fixed. Thanks to all those who responded! – mmo Oct 11 '21 at 20:14

0 Answers0