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:
- You can set any Java 9+ only options using the
JDK_JAVA_OPTIONS
environment variable. This environment variable is automatically read by thejava
launcher for Java 9+. - 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
As of July 2022, the latest version of the bind-api and jaxb-runtime is 4.0.0. So you can also use
<version>4.0.0</version>
…within those dependency clauses. But if you do so, the package names have changed from javax.xml.bind...
to jakarta.xml.bind...
. You will need to modify your source code to use these later versions of the JARs.
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"
}
- Details
- Written by
- Last Updated on 11 May 2019 | Print Email
In Java web application development, you may encounter the following error when starting the server (e.g. Apache Tomcat):
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException ... ... Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException ... ... ...
This error would look something like this in Eclipse IDE:
It is because the JAXB library (Java Architecture for XML Binding) is missing in the classpath. JAXB is included in Java SE 10 or older, but it is removed from Java SE from Java 11 or newer –moved to Java EE under Jakarta EE project.
That means if you encounter JAXBException error, it’s very much likely that you are using Java 11 or newer for your project – or at least the server is running under on that Java version. So to fix this error, you have to options:
1. Use older Java version like JDK 8, 9 or 10 which still include the JAXB library by default. Or:
2. Specify an additional dependency in your project’s pom.xml file as follows:
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency>
In case you don’t use Maven, you can manually download the JAXB JAR file from Maven repository, and add it to the project’s classpath:
Then restart the server, the error will go way.
That’s the solution to fix the error java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException.
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.
Add comment
If you are upgrading your Java application from a lower version to Java 11, you may get the following error:
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException ... ... Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException ... ... ...
The JAXB APIs are considered to be Java EE APIs, and therefore are no longer contained on the default class path in Java SE 9. In Java 11 they are completely removed from the JDK. If you are using Java 9, then the JAVA SE module named java.se is in the classpath but this module doesn’t contain the JAVA EE APIs. While from Java 11 onwards, the jaxb apis, namely:
-
jaxb-api
-
jaxb-core
-
jaxb-impl
-
activation, etc
are completely removed from the Java installation. Hence, to resolve the above error, you must include the jaxb-api jar file in the classpath of your project/application.
For Maven Projects:
If you are using Maven for handling dependencies in your Java project, you will have to add the following additional dependency in your pom.xml file.
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
This will include the jaxb-api Jar file in your project when you will build your maven java project.
For Gradle Projects:
If you use Gradle to build your project, then add the following line to your build.gradle file,
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
For SBT Projects:
If you use SBT build tool to compile and build your java project, then add the following line to your build file,
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.0"
For IVY Projects:
If you use ivy for building your java project, then add the following code line to your ivy.xml file:
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.3.0"/>
If you don’t use any build tool
If you are not using any build tool, then you can download the jar file from the following link: JAXB-API 2.3.0 MVN Repository and add it to your project’s classpath
Once you have made the following changes, restart your Java application, and the error should be resolved. So this was the solution for the java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException Error. If you are not able to understand anything, feel free to comment, and we will help you resolve your error.
Conclusion
To summarise, the «java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException» problem in Java 11 is irritating, but it is fixable. This error happens as a result of the loss of JAXB from Java 11, but it is fixable by adding the required dependencies to your project. You can effectively resolve this error and proceed with your Java 11 development tasks by following the methods outlined in this piece. Remember to maintain your files up to date to avoid making similar mistakes in the future.
Frequently Asked Questions
1. What is the cause of «java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException» in Java 11?
Java 11 removed the JAXB (Java Architecture for XML Binding) module, causing this error when running code that depends on it.
2. How can I resolve «java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException» in Java 11?
You can resolve this error by adding the JAXB module to your project’s dependencies. For example, if using Maven, add the following dependency to your pom.xml file:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
3. Can I still use JAXB in Java 11?
You can still use JAXB in Java 11 by adding it as a separate module or dependency to your project.
4. What are the alternatives to JAXB in Java 11?
Alternatives to JAXB in Java 11 include using other XML binding frameworks such as Jackson or XMLBeans, or manually parsing XML using the built-in XML parsing capabilities of Java.
5. What is the error in Javax XML bind?
The error in Javax XML bind typically occurs when the JAXB library is not included in the classpath or when the version of the library is not compatible with the version of the Java runtime environment.
You Might Also Like
-
[SOLVED] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
-
[SOLVED] Caused by: java.lang.ClassNotFoundException: javax.xml.ws.WebServiceFeature in Java 11
-
How to convert ZonedDateTime to Date in Java?
-
Log4j2 Programmatic Configuration in Java Class
Error warnings in Java are no longer a strange problem for us. Among these errors, “java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException” is a common warning that many people often encounter when starting the “Apache Tomcat” server.
If you meet the above error in beginning this server, this article will be the fastest way to fix it for you. Read on for details!
When Is This Error Occurring?
Each alert type carries a message of its own, and you need to recognize what kind of problem this alert is showing. In the process of starting the “Apache Tomcat” server, you will easily encounter an error displayed with the following content:
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException...... Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
How Can This Problem Be Resolved?
The fastest way to fix java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException error is to add dependencies to your “pom.xml”.
If you are wondering about creating cumbersome code? Don’t worry because our guide will help you through the whole process. Refer to the details below to receive the most accurate instructions!
Solution 1 – Please Add Dependency IIIIn “pom.xml”
With this solution, you only need to use this dependency add in your “pom.xml” section:
javax.xml.bind jaxb-api 2.3.1
Solution 2 – Define Dependency List
In this second method, you only define the following dependency list:
javax.xml.bind jaxb-api 2.3.0 com.sun.xml.bind jaxb-impl 2.3.0 org.glassfish.jaxb jaxb-runtime 2.3.0 javax.activation activation 1.1.1
Solution 3 – Method For Versions From “jdk 9” And Above
Your version is also a factor in helping you find the most appropriate fix. If you are utilizing a version from “jdk 9” or later, only add the following dependency right into the “pom.xml” section:
javax.xml.bind jaxb-api 2.3.0
Conclusion
After this article, if you still encounter the error “java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException” in the future, then confidently fix it with our methods. If you still have difficulties using Java, feel free to let us know in the discussion below!
Related articles
- ブラックジャックをプレイすることを検討しています。ロンド辞書 ロングド辞書 คำศัพท์
投稿 今すぐオンラインで完全無料のブラック ジャックをプレイ あなたの数日間のギャンブル事業 無料のブラックジャック ゲームの評価 知っておくべきブラックジャックの言葉 しかし、そうではありません。分離すべきではないセットがいくつかあります。それらを着用すると、成功する可能性があまり残らないからです。新鮮なブローカーは、表向きのクレジット 1 枚と裏向きのカード 1 枚から始まります。ボールプレーヤーは、バイヤーシードと呼ばれる電子メールから自分自身でシリーズを決定するか、新しいローカルカジノで利用可能な無計画なデフォルトを許可します。攻撃する、残る、別れる Post Views: 81 Related Posts:numerous Twice Diamond Ports Paypal Gambling…Diese Besten Search mr bet casino 10€ engine Pay Online…several Double Diamond Slots Paypal Local casino Number…multiple Double Diamond Harbors Paypal Gambling…multiple Double Diamond Ports Paypal Local casino List…several Double Diamond Ports Paypal Casino […]
- Betfinal Gambling doubledown casino download for pc establishment As much as $200 Reload Extra
Content Closing Opinion From the Betfinal Local casino Review Cons Out of Crypto Gambling establishment Is actually Bitcoin Casinos Safe? The fresh driver as well as entertains its repeated players with many lingering campaigns. Even when Betfinal is mainly an excellent bookmaker, moreover it have an entire-fledged casino. There are not any first and you […]
- 50 Free Spins! Grand Extra On the Tarot Fate Slot
Articles Well-known Slots For no Put Bonuses Slots Ninja Casino No deposit Extra Https: Tips Enjoy 100 percent free Ports That have Added bonus And 100 percent free Spins? 100 percent free Revolves Arrows Line Betsoft Rival Simultaneously, they are able to enhance the total choice a player tends to make. And PayPal, most other […]
- Learn more about Just how Online slots Performs
Content Club Riches Gambling establishment: 50 Totally free Spins No-deposit Cash Lab Megaways Because of the Isoftbet Red-dog Gambling enterprise Goldfish Position For new And you may Established Professionals Take pleasure in Lotsa Harbors – Totally free Las vegas Casino Slot machines and start rotating free harbors! If you would like software one to always […]
- The purchase price Is good spin and win slots American Game Let you know
Articles Final thoughts On the Totally free 30 Revolves No-deposit Is there The absolute minimum Put I must Make To utilize Totally free Spins? Download Versus Zero Free download Revolves From there, one can use them for the any of the casino’s slots. Make sure to browse the spin and win slots fine print of […]
Post Views:
167
JAXBException is the root exception class for all the JAXB exceptions. Generally this exception occurred when the implemented code is not fulfill the pre-requisite for JAXB related dependencies.
Constructors
JAXBException class having following constructors.
- JAXBException(String msg): Construct exception with detail message..
- JAXBException(String msg, String errorCode) : This construct exception with detail message with error code.
- JAXBException(String msg, String errorCode, Throwable exception) : Construct detail message with error code and stacktrace of linked exception stacktrace.
- JAXBException(String msg, Throwable exception) :Construct exception with detail message and stacktrace of linked exception.
- JAXBException(Throwable exception) : Construct exception with stacktrace of linked exception.
Problem
This JAXBException occurred in your code because on runtime JAXB is not able to find JAXB-API related dependency.
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. - with linked exception: [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278) at javax.xml.bind.ContextFinder.find(ContextFinder.java:421) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) at com.facingIssuesOnIT.domain.EmployeeJAXBTest.marshal(EmployeeJAXBTest.java:23) at com.facingIssuesOnIT.domain.EmployeeJAXBTest.main(EmployeeJAXBTest.java:15) Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122) at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276) ... 5 more
Solutions
To implement JAXB marshalling and unmarshalling in your application, you need to add following dependencies in you code. As above exception message explained “JAXB-API has not found in module or class path” this exception occurred when you forget to add JAXB-API dependency.
<dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>2.3.0.1</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.25.0-GA</version> </dependency>
Conclusion
In this post , You learn about the JAXBException cases to occurred, different constructors and example to solve JAXB-API has not found in module or class path” JAXBException.
Let me know your thought to about this post.
Happy Learning !!!