XJC Maven Plugin(jaxb2-maven-plugin) Java 11 Migration Issues
Asked Answered
E

5

25

I am currently working on java 11 migration project where jaxb2-maven-plugin has been used for XJC task. As XJC executable is not present in the JDK 11 version, I am getting below mentioned errors.

    [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc (xjc-schema1) on project paymaster-service: Execution xjc-schema1 of goal org.codehaus.mojo:jaxb2-maven-plugin:2.2
:xjc failed: A required class was missing while executing org.codehaus.mojo:jaxb2-maven-plugin:2.2:xjc: com/sun/codemodel/CodeWriter
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:jaxb2-maven-plugin:2.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/voletis/.m2/repository/org/codehaus/mojo/jaxb2-maven-plugin/2.2/jaxb2-maven-plugin-2.2.jar
[ERROR] urls[1] = file:/C:/Users/voletis/.m2/repository/javax/xml/bind/jaxb-api/2.2.11/jaxb-api-2.2.11.jar
[ERROR] urls[2] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-core/2.2.11/jaxb-core-2.2.11.jar
[ERROR] urls[3] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
[ERROR] urls[4] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
[ERROR] urls[5] = file:/C:/Users/voletis/.m2/repository/org/glassfish/jaxb/jaxb-jxc/2.2.11/jaxb-jxc-2.2.11.jar
[ERROR] urls[6] = file:/C:/Users/voletis/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M3/qdox-2.0-M3.jar
[ERROR] urls[7] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[8] = file:/C:/Users/voletis/.m2/repository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[9] = file:/C:/Users/voletis/.m2/repository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] urls[10] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[11] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[12] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[13] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[14] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.5/plexus-compiler-api-2.5.jar
[ERROR] urls[15] = file:/C:/Users/voletis/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[16] = file:/C:/Users/voletis/.m2/repository/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] : com.sun.codemodel.CodeWriter
[ERROR] -> [Help 1]
[ERROR]

Below is my pom.xml

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxb2-maven-plugin</artifactId>
   <version>2.2</version>
   <executions>
      <execution>
         <id>xjc-schema1</id>
         <goals>
            <goal>xjc</goal>
         </goals>
         <configuration>
            <target>2.2</target>
            <schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
            <packageName>app.test.services.submitpayment.request</packageName>
            <clearOutputDir>false</clearOutputDir>
         </configuration>
      </execution>
</plugin>

I have added necessary dependencies like JAXB, JAXB-IMPL, etc., as per java 11 requirements. But still not able to fix the issues. Do you have any suggested fix for this ? Thank in Advance.

Equidistant answered 25/2, 2019 at 15:13 Comment(0)
E
5

I have fixed this issue by following below reference link.

https://github.com/davidmoten/jax-maven-plugin

As per the above tutorial reference, I have modified my plugin as below and i am able to fix this.

<plugin>
   <groupId>com.github.davidmoten</groupId>
   <artifactId>jax-maven-plugin</artifactId>
   <version>VERSION_HERE</version>

   <executions>
      <execution>
         <id>xjc-schema1</id>
         <goals>
            <goal>xjc</goal>
         </goals>
         <configuration>
            <target>2.2</target>
            <schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
            <packageName>app.test.services.submitpayment.request</packageName>
            <clearOutputDir>false</clearOutputDir>
         </configuration>
      </execution>
   </executions>
</plugin>
Equidistant answered 28/2, 2019 at 8:2 Comment(4)
Hi, remove the dependencies block as it's not needed and the the configuration entries need to be in <argument> elements as per the xjc CLI command. May as well update the version to 0.1.6 (or just write VERSION_HERE so people use latest).Deckhouse
Moving from jaxb2-maven-plugin to jax-maven-plugin resolved a lot of issues during schemagen for my Java 11 project. Each recent version of jaxb2-maven-plugin caused a different exception.Nerland
Thanks, however @DaveMoten, i tried using the plugin it didn't throw any error but there were no classes generated under the said package name :-(, so fails silently for meRwanda
@AshwiniRao can't help you without more details. Raise an issue on project site and we can discuss there.Deckhouse
P
38

jaxb2-maven-plugin 2.5.0 is now compatible with Java 11:

Pothouse answered 10/7, 2019 at 14:16 Comment(1)
I am using version 2.5.0 and Java 11. I still face the same issue. :-(Dirtcheap
E
10

I had issues with making jaxb working with maven and Java 11 too. My solution looks as follows:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>2.5.0</version>
  <executions>
    <execution>
      <id>xjc</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>xjc</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <packageName>de.powerstat.my.generated</packageName>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>com.sun.activation</groupId>
      <artifactId>javax.activation</artifactId>
      <version>1.2.0</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.3</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-core</artifactId>
      <version>2.3.0.1</version>
    </dependency>

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-xjc</artifactId>
      <version>2.3.3</version>
    </dependency>

  </dependencies>
</plugin>

Hope this helps others.

Eulogize answered 5/6, 2020 at 16:16 Comment(0)
E
5

I have fixed this issue by following below reference link.

https://github.com/davidmoten/jax-maven-plugin

As per the above tutorial reference, I have modified my plugin as below and i am able to fix this.

<plugin>
   <groupId>com.github.davidmoten</groupId>
   <artifactId>jax-maven-plugin</artifactId>
   <version>VERSION_HERE</version>

   <executions>
      <execution>
         <id>xjc-schema1</id>
         <goals>
            <goal>xjc</goal>
         </goals>
         <configuration>
            <target>2.2</target>
            <schemaFiles>SubmitPaymentBatch/SubmitPaymentRequest.xsd</schemaFiles>
            <packageName>app.test.services.submitpayment.request</packageName>
            <clearOutputDir>false</clearOutputDir>
         </configuration>
      </execution>
   </executions>
</plugin>
Equidistant answered 28/2, 2019 at 8:2 Comment(4)
Hi, remove the dependencies block as it's not needed and the the configuration entries need to be in <argument> elements as per the xjc CLI command. May as well update the version to 0.1.6 (or just write VERSION_HERE so people use latest).Deckhouse
Moving from jaxb2-maven-plugin to jax-maven-plugin resolved a lot of issues during schemagen for my Java 11 project. Each recent version of jaxb2-maven-plugin caused a different exception.Nerland
Thanks, however @DaveMoten, i tried using the plugin it didn't throw any error but there were no classes generated under the said package name :-(, so fails silently for meRwanda
@AshwiniRao can't help you without more details. Raise an issue on project site and we can discuss there.Deckhouse
C
1

I've just found a workaround for problems with using jaxb2-maven-plugin with Java 11. It consists of adding extra dependencies in pom.xml and adding an extra, dummy XSD file to the project, next to proper XSD files. I've put it altogether in my blog-post here: https://artofcode.wordpress.com/2019/02/26/jaxb2-maven-plugin-2-4-and-java-11/

Crissy answered 27/2, 2019 at 18:32 Comment(0)
T
0

I was able to solve the issue for JDK11 by adding all dependencies which are listed here: https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/pom.xml#L251-L290 which the apache.cxf project uses in their example projects starting for JDK9

Thylacine answered 27/3, 2020 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.