Search code examples
javaspring-bootmavenjarclasspath

java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts - maven spring-boot


java.lang.NoClassDefFoundError: io/jsonwebtoken/Jwts

When I run locally with mvn spring-boot:run , there's no problem.

But when I package my application into a fully executable jar with mvn clean install and then run the jar as a systemd service, I get this error seen above.

It comes from this line:

String user = Jwts.parser()...

Some information: Version of this package that the issue occurs: 0.11.1 Platform: Ubuntu 18.04 Related dependency in maven pom.xml:

<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-impl</artifactId>
    <version>0.11.1</version>
</dependency>

Also I checked the generated jar file, the dependency jjwt-impl.0.11.1 is there:

BOOT-INF.lib.jjwt-impl-0.11.1.jar
BOOT-INF.lib.jjwt-api-0.11.1.jar
BOOT-INF.lib.jjwt-jackson-0.11.1.jar

Don't know how to solve this. I thought just adding the io.jsonwebtoken to maven dependency would solve all things related to classpath etc..

Im applying spring-boot-maven-plugin package to create the jar and command mvn clean install to create the fully executable jar file.

When I printed out the classpath from within the jar application, it only points to that jar file itself, and nowhere else. Im not sure if that is how it should be. I thought all the dependencies should be compiled to that same jar, so in that sense it could make sense.

Also made an issue to official jjwt library here: https://github.com/jwtk/jjwt/issues/599 But this might be a problem related more to spring-boot?


Solution

  • Got this fixed by updating maven package spring-boot-starter-parent from 1.5.2.RELEASE to 2.3.0.RELEASE version