3

I have an API that receives a JWT token for authorization.

Once it starts the process of working with the token to authenticate it throws this error: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter

I read that in Java 11 they removed the java.xml.bind library from the JDK. I added these two dependencies as suggested in the answer: implementation "jakarta.xml.bind:jakarta.xml.bind-api:3.0.0" and implementation "org.glassfish.jaxb:jaxb-runtime:3.0.0".

Also tried implementation "jakarta.xml.bind:jakarta.xml.bind-api:3.0.0" and implementation 'com.sun.xml.bind:jaxb-impl:3.0.0'.

But I still get the same error and I cannot find any other solution to this.

I use Java 11 and Spring boot 2.6.6.

Thanks for the help

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
andreootid
  • 59
  • 1
  • 1
  • 3

3 Answers3

5

i solved this problem by removing old jjwt 0.9.1 and add these

implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Amin garo
  • 51
  • 1
  • 2
3

Use version 2.x of those dependencies. In version 3.x, the leading prefix javax was replaced by jakarta. The same occurred for other Java EE / Jakarta EE APIs.

Rob Spoor
  • 6,186
  • 1
  • 19
  • 20
  • But in the first option where I used version 3.x I used jakarta. – andreootid Apr 15 '22 at 18:35
  • Yes, there are three types for the Java EE and Jakarta EE APIs: the first use groupIds that starts with `javax`. Those are all Java EE. Then these were handed over to the Jakarta project. These use groupIds that start with `jakarta`. The first version of these APIs still use package prefix `javax`, probably for easier transition. Later versions changed the package prefix to `jakarta`. – Rob Spoor Apr 15 '22 at 18:41
  • Yes, but we already had the jakarta V. 3.X dependency so unfortunately I cannot downgrade the library version. So using this one jakarta.xml.bind:jakarta.xml.bind-api:3.0.0 should be fine right? – andreootid Apr 15 '22 at 20:20
  • Unfortunately, that comes with packages with the `jakarta` prefix. You'll still get the same error. Since you can only get one version of a library, you probably need to use the old dependency instead: https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api. If you need an implementation and you still need the version 3 Glassfish dependency, try version 2.x of https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl. – Rob Spoor Apr 16 '22 at 11:20
  • 3
    I found that we use external library io.jsonwebtoken:jjwt:0.9.1 Base64Codec class to parse the encoded token. Inside the class it calls javax.xml.bind.DatatypeConverter from javax.xml.bind:javx-api:2.3.1. Maybe that's why it doesn't work changing the jakarta version because it anyways uses this one. Because searching the libraries I have the DatatypeConverter class in jakarta 3.X but it uses the one from javax. – andreootid Apr 18 '22 at 15:31
  • This solved my issue with docx4j / docx-stamper relying on JAXB – downvoteit Aug 15 '23 at 21:48
0

As @andréootide said JJWT needs DatatypeConverter from javax.xml.bind..... I solved my problem by adding

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
Ballo Ibrahima
  • 461
  • 4
  • 10