java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter while decoding JWT token with Java 11

Viewed 298

When calling this method for decoding a JWT token javax.xml.bind.DatatypeConverter.parseBase64Binary(encoded) I get this exception:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)


Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at io.jsonwebtoken.impl.Base64Codec.decode(Base64Codec.java:26)
at io.jsonwebtoken.impl.Base64UrlCodec.decode(Base64UrlCodec.java:78)
at io.jsonwebtoken.impl.AbstractTextCodec.decodeToString(AbstractTextCodec.java:36)
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:251)
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:481)
at io.jsonwebtoken.impl.DefaultJwtParser.parseClaimsJws(DefaultJwtParser.java:541)

I have this external libraries on the project among others:

implementation "jakarta.xml.bind:jakarta.xml.bind-api:3.0.1"
  implementation "org.glassfish.jaxb:jaxb-runtime:3.0.2"
  io.jsonwebtoken:jjwt:0.9.1
javax.xml.bind:jaxb-api:2.3.1

In the external library javax.xml.bind:jaxb-api:2.3.1 I can find the javax/xml/bind/DatatypeConverter used in the code so I don't understand why I'm getting the NoClassDefFoundError.

I use Java 11 on the project and spring boot.

Thanks for the help.

1 Answers

Add this line in gradle.

implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'

Downgrade your javax.xml.bind:jaxb-api With specific version.

Related