jaxb2-maven-plugin 2.4 and Java 11

I decided to investigate how to use jaxb2-maven-plugin 2.4 with Java 11. It’s still not easy to make these things working together but this time I was more lucky (see my previous attempt with Java 10) and here is a ready-to-use receipt how to do it!


Java version:

$ java --version
openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

Maven version:

$ mvn --version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 11.0.2, vendor: Oracle Corporation
Java home: .../jdk-11.0.2
Default locale: pl_PL, platform encoding: UTF-8
OS name: "linux", ..., family: "unix"


With Java 11 (most likely the same would work with Java 10) we need to explicitly add dependencies required to have working JAXB, because many things were removed from Java in version 11:

Moreover we need to explicitly declare some Maven plugins to make sure we’re using latest versions of these plugins which are ready for Java 11.

Please note the <sources> tag in configuration section for jaxb2-maven-plugin. It consists of 2 elements. One is the path to the desired XSD (src/main/xsd/your-file.xsd) – change it according to your requirements. The other element (src/main/xsd/dummy.xsd) is a workaround for some strange issue jaxb2-maven-plugin has when working with Java 11.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">




Note that without the line 70 (<source>src/main/xsd/dummy.xsd</source>) the build will fail with the following error:

[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.4:xjc (xjc) on project ...: Prefix '' is already bound to '' -> [Help 1]


As far as I know the content of this file is just:

<xs:schema id="Dummy" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Dummy"> 
                <xs:element name="test"/> 

You need to put this file into src/main/xsd folder.

And now things are working!!! 🙂 Run maven and make use of model classes generated from XSD file.

The only difference comparing to case when using Java 8 is that now we see these warning messages as the very first lines printed when executing mvn package command:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
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

My guess is this is not dangerous and it will be solved by newer Maven release.

About krzysztoftomaszewski

I've got M.Sc. in software engineering. I graduated in 2005 at Institute of Computer Science, Warsaw University of Technology, Faculty of Electronics and Information Technology. I'm working on computer software design and engineering continuously since 2004.
This entry was posted in Java, XML and tagged , , , . Bookmark the permalink.

10 Responses to jaxb2-maven-plugin 2.4 and Java 11

  1. Patrick says:

    You are a genius! Thank you! By the way, I do not need the dummy file.

  2. Person says:

    Awesome, thank you! This worked for me. But I’m curious as to why the dummy file is needed?

  3. Levsha says:

    Thank you very much! How do you understand use dummy.xsd?

  4. vinis says:

    In my scenario using “c**.xsd” and “bi**.xjb” files but its not properly generate the class due to not use ‘bi**.xjb’ file.


    Please I need to your suggestion.

  5. naveen kumar says:

    Thank you for the tip. I am trying to generate from wsdl file but getting error as my wsdl has “soapenc:arrayType” complext data type. Can you please tell me a way to fix

  6. utcmaterial says:

    Thanks for the article I hava a question is this acheivable with Oracle JDK11 or its time to dich the good old witch and embrasse the OpenJDK?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s