Proper fix for Java 10 complaining about illegal reflection access by jaxb-impl 2.3.0?

Solution 1:

jaxb-ri runtime uses ClassLoader#defineClass / Unsafe#defineClass to do some bytecode modification in runtime to optimize performance. ClassLoader#defineClass is tried first which causes the warning.

This legacy optimization is removed completely in jaxb-ri master (after 2.3.0, not released yet).

To disable this optimization for 2.3.0, set system property com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize.

After next jaxb-ri release updating to newest version will remove the warning. jaxb-core artifact will be discontinued in favor for JPMS support. Correct pom will look like:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.4.0</version> 
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.4.0</version> 
</dependency>

If you wish to try early, you can pick latest promoted build from: https://maven.java.net/content/groups/promoted/org/glassfish/jaxb/jaxb-runtime/

Solution 2:

kudos to @Roman Grigoriadi , He was right, the updated 2.4 version fixes the warning issues.

Just add the dependencies below to the pom file

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.4.0-b180830.0359</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jaxb</groupId>
  <artifactId>jaxb-runtime</artifactId>
  <version>2.4.0-b180608.0325</version>
</dependency>

Solution 3:

I just spent half a day going through old blogs and posts about this subject, most outdated and not working. Or only working with warnings at runtime. As of december 2020, the following works with Java 15, without any errors or warnings:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

Solution 4:

To make JAXB 2.3.3 work with JDK 16 (ie work with JDK 1.8 to 17 EA): ALWAYS add 'Multi-Release: true' to your MANIFEST.MF !

see my comments:

https://github.com/eclipse-ee4j/jaxb-ri/issues/1197#issuecomment-810908755

Here are my concrete maven (explicit) dependencies to use JAXB 2.3.3 in my project:

<!-- JAXB 2.3.3 (jdk 8+) -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.3</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.3</version>
    </dependency>

    <!-- JAXB dependencies -->
    <dependency>
        <groupId>jakarta.activation</groupId>
        <artifactId>jakarta.activation-api</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>com.sun.activation</groupId>
        <artifactId>jakarta.activation</artifactId>
        <version>1.2.2</version>
    </dependency>

    <dependency>
        <groupId>com.sun.istack</groupId>
        <artifactId>istack-commons-runtime</artifactId>
        <version>3.0.11</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.fastinfoset</groupId>
        <artifactId>FastInfoset</artifactId>
        <version>1.2.18</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.staxex</groupId>
        <artifactId>stax-ex</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>txw2</artifactId>
        <version>2.3.3</version>
    </dependency>