Lỗi java.lang.classnotfoundexception javax.xml.bind.datatypeconverter

When using the Microsoft SQL Server driver this error typically indicates you are using a driver version that is not compatible with the Java version being used in DbVisualizer. Check what Java version is used in Help->About.

First make sure you are using the latest available driver version.

In DbVisualizer 13.0 and later you can change the driver version and download the new version from Tools->Driver Manger, see for how to do this.

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:

javax.xml.bind jaxb-api 2.3.0

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:

GroupDocs.Viewer for Java API depends on javax.xml.bind for working with PDF files, that is; in case of using Java 9 and above and if the program is required to work with PDF file types, it is required to add reference of javax.xml.bind in the project’s class path, because the library was removed from standard Java library.

Symptoms

You may get exception like java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter.

Solution

The solution is actually very simple as detailed below.

  • Download jaxb-api-2.3.0.jar library as JAR file from Maven repository.
  • Put the file into your project directory.
  • Reference the jaxb-api-2.3.0.jar in the class path of the project.

Alternatively, you can add the dependency in the pom.xml and let the project resolve the dependency via maven.

While following the instructions in the Content Manager OnDemand REST Services Implementation Guide to create a connection pool, the following error occurred:

Loading template file: /restcfgdir/cmodtest.tmpl Template file: /restcfgdir/cmodtest.tmpl poolFile name -> /restcfgdir/pools/odtest.conn Creating pool file odtest.conn..... Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter at com.unicom.cm.od.rest.Decrypter.encrypt[Decrypter.java:55] at com.unicom.cm.od.rest.ODRESTAdmin.writeConnectionFile[ODRESTAdmin.java:462] at com.unicom.cm.od.rest.ODRESTAdmin.main[ODRESTAdmin.java:116] Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter 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] ... 3 more

Cause

This error is caused by the fact that Java versions 11+ removed all of the J2EE modules of which JAXB was one. So, in order to create the REST connection pool with the ODRESTAdmin.jar [which depends on jaxb-api.jar] with Java 11+, you need to download the standalone distribution of JAXB [javaee.github.io] from the web at //javaee.github.io/jaxb-v2/ and set it in your CLASSPATH.

Resolving The Problem

When specifying -jar on the command line, the CLASSPATH is ignored. Therefore, when using Java 11+, the command that includes the -jar as it is provided in the REST Services Implementation Guide sample commands will not successfully resolve the location of the jaxb-api.jar. Instead, use a command similar to the following:

java -classpath /arstmp/jaxb-api.jar:/opt/ibm/ondemand/V10.5/jars/ODRESTAdmin.jar com.unicom.cm.od.rest.ODRESTAdmin createPool -configDir /restcfgdir -template cmodtest.tmpl -odinstance archive -odUser restconsumer -odPassword passw0rd -poolName odtest

Java 8 includes the J2EE modules. Java 9 and 10 have deprecated them but still include them.

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEPCD","label":"Content Manager OnDemand for Multiplatforms"},"ARM Category":[{"code":"a8m0z0000001gP1AAI","label":"technote"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"},{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSQHWE","label":"Content Manager OnDemand for z\/OS"},"ARM Category":[{"code":"a8m0z0000001gP1AAI","label":"technote"}],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"},{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSB2EG","label":"Content Manager OnDemand for i"},"ARM Category":[{"code":"a8m0z0000001gP1AAI","label":"technote"}],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Chủ Đề