Skip to content
Fix Code Error

How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

March 13, 2021 by Code Error
Posted By: Anonymous

I have some code that uses JAXB API classes which have been provided as a part of the JDK in Java 6/7/8. When I run the same code with Java 9, at runtime I get errors indicating that JAXB classes can not be found.

The JAXB classes have been provided as a part of the JDK since Java 6, so why can Java 9 no longer find these classes?

Solution

The JAXB APIs are considered to be Java EE APIs and therefore are no longer contained on the default classpath in Java SE 9. In Java 11, they are completely removed from the JDK.

Java 9 introduces the concepts of modules, and by default, the java.se aggregate module is available on the classpath (or rather, module-path). As the name implies, the java.se aggregate module does not include the Java EE APIs that have been traditionally bundled with Java 6/7/8.

Fortunately, these Java EE APIs that were provided in JDK 6/7/8 are still in the JDK, but they just aren’t on the classpath by default. The extra Java EE APIs are provided in the following modules:

java.activation
java.corba
java.transaction
java.xml.bind  << This one contains the JAXB APIs
java.xml.ws
java.xml.ws.annotation

Quick and dirty solution: (JDK 9/10 only)

To make the JAXB APIs available at runtime, specify the following command-line option:

--add-modules java.xml.bind

But I still need this to work with Java 8!!!

If you try specifying --add-modules with an older JDK, it will blow up because it’s an unrecognized option. I suggest one of two options:

  1. You can set any Java 9+ only options using the JDK_JAVA_OPTIONS environment variable. This environment variable is automatically read by the java launcher for Java 9+.
  2. You can add the -XX:+IgnoreUnrecognizedVMOptions to make the JVM silently ignore unrecognized options, instead of blowing up. But beware! Any other command-line arguments you use will no longer be validated for you by the JVM. This option works with Oracle/OpenJDK as well as IBM JDK (as of JDK 8sr4).

Alternate quick solution: (JDK 9/10 only)

Note that you can make all of the above Java EE modules available at run time by specifying the --add-modules java.se.ee option. The java.se.ee module is an aggregate module that includes java.se.ee as well as the above Java EE API modules. Note, this doesn’t work on Java 11 because java.se.ee was removed in Java 11.


Proper long-term solution: (JDK 9 and beyond)

The Java EE API modules listed above are all marked @Deprecated(forRemoval=true) because they are scheduled for removal in Java 11. So the --add-module approach will no longer work in Java 11 out-of-the-box.

What you will need to do in Java 11 and forward is include your own copy of the Java EE APIs on the classpath or module path. For example, you can add the JAX-B APIs as a Maven dependency like this:

<!-- API, java.xml.bind module -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>

<!-- Runtime, com.sun.xml.bind module -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

See the JAXB Reference Implementation page for more details on JAXB.

For full details on Java modularity, see JEP 261: Module System

For Gradle or Android Studio developer: (JDK 9 and beyond)

Add the following dependencies to your build.gradle file:

dependencies {
    // JAX-B dependencies for JDK 9+
    implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
    implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"
}
Answered By: Anonymous

Related Articles

  • Vue.JS & Spring Boot - Redirect to homepage on 404
  • Examples of GoF Design Patterns in Java's core libraries
  • How to generate JAXB classes from XSD?
  • javax.xml.bind.JAXBException: Class *** nor any of…
  • Identifying and solving…
  • How do I install Java on Mac OSX allowing version switching?
  • TLS 1.3 server socket with Java 11 and self-signed…
  • Java 11 package javax.xml.bind does not exist
  • What does "Could not find or load main class" mean?
  • [Vue warn]: Error in render: "TypeError: Converting…
  • react-table has a issue with rendering in next.js
  • Downloading Java JDK on Linux via wget is shown…
  • ClassNotFoundException:…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • UnsatisfiedDependencyException: Error creating bean…
  • Launching Spring application Address already in use
  • Simple conversion between java.util.Date and…
  • Aurelia UX showcase app fails to load
  • Using StringWriter for XML Serialization
  • How to prevent scrolling the whole page?
  • What is the JSF resource library for and how should…
  • Autowiring fails: Not an managed Type
  • Maven Could not resolve dependencies, artifacts…
  • java IO Exception: Stream Closed
  • How to filter a RecyclerView with a SearchView
  • What is a NullReferenceException, and how do I fix it?
  • java.lang.RuntimeException: Unable to instantiate…
  • Specifying java version in maven - differences…
  • Why do I get java.lang.AbstractMethodError when…
  • Ukkonen's suffix tree algorithm in plain English
  • What are the undocumented features and limitations…
  • How to use java.net.URLConnection to fire and handle…
  • Uncaught TypeError: c.querySelectorAll is not a function
  • How to install JSTL? The absolute uri:…
  • javax.el.PropertyNotFoundException: Property 'foo'…
  • javax.faces.application.ViewExpiredException: View…
  • JavaFX and OpenJDK
  • JAXB: How to ignore namespace during unmarshalling…
  • Aurelia CLI, babel runtime and async transforms
  • org.hibernate.MappingException: Unknown entity
  • What does a "Cannot find symbol" or "Cannot resolve…
  • For-each over an array in JavaScript
  • Which is the best library for XML parsing in java
  • How to add Typescript to a Nativescript-Vue project?
  • What causes and what are the differences between…
  • What are the best JVM settings for Eclipse?
  • MessageBodyWriter not found for media…
  • How does PHP 'foreach' actually work?
  • How do servlets work? Instantiation, sessions,…
  • Failed to install android-sdk:…
  • commandButton/commandLink/ajax action/listener…
  • Android Studio 4.2.1 NullPointer Exception on startup
  • AppCompat v7 r21 returning error in values.xml?
  • Where to place and how to read configuration…
  • Could not resolve placeholder in string value
  • What's the difference between eval, exec, and compile?
  • How do I import the javax.servlet API in my Eclipse project?
  • What does "Fatal error: Unexpectedly found nil while…
  • I can't understand why this JAXB…
  • Can not initialize the default wsdl from classpath:wsdl
  • How to access parameters in a RESTful POST method
  • How to use a servlet filter in Java to change an…
  • What is a classpath and how do I set it?
  • Handling errors with the (now default) Ember Data…
  • Jetpack Compose and Hilt Conflict
  • Name [jdbc/mydb] is not bound in this Context
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • How to solve java.lang.NoClassDefFoundError?
  • Spring schemaLocation fails when there is no…
  • Why am I getting a "401 Unauthorized" error in Maven?
  • HTTP Status 500 - org.apache.jasper.JasperException:…
  • How to use Servlets and Ajax?
  • Tomcat 7 "SEVERE: A child container failed during start"
  • How to find out client ID of component for ajax…
  • Ubuntu apt-get unable to fetch packages
  • java - path to trustStore - set property doesn't work?
  • laravel vuejs/axios put request Formdata is empty
  • Understanding PrimeFaces process/update and JSF…
  • PHP parse/syntax errors; and how to solve them
  • The superclass "javax.servlet.http.HttpServlet" was…
  • How do you parse and process HTML/XML in PHP?
  • Spring Boot with ElasticSearch in Groovy: WebClient…
  • data.table vs dplyr: can one do something well the…
  • Maven does not find JUnit tests to run
  • Spring Integration Dynamic XML through JAXB or other tool
  • Why does C++ code for testing the Collatz conjecture…
  • My Application Could not open ServletContext resource
  • How to use PrimeFaces p:fileUpload? Listener method…
  • What is the difference between JVM, JDK, JRE & OpenJDK?
  • What is Ember RunLoop and how does it work?
  • How to do a SOAP Web Service call from Java class?
  • org.springframework.beans.factory.NoSuchBeanDefiniti…
  • Android- Error:Execution failed for task…
  • Neither BindingResult nor plain target object for…
  • NoClassDefFoundError on Maven dependency
  • java.lang.UnsupportedClassVersionError Unsupported…
  • Why is it that "No HTTP resource was found that…
  • No @XmlRootElement generated by JAXB
  • Smart way to truncate long strings
  • setting JAVA_HOME & CLASSPATH in CentOS 6

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

git undo all uncommitted or unsaved changes

Next Post:

Understanding unique keys for array children in React.js

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error