Fixed: "Unable to load class named [io.jsonwebtoken.impl.security.KeysBridge]" in JJWT
A Java program that creates a JWT with JJWT compiled without a problem and then stopped with Unable to load class named [io.jsonwebtoken.impl.security.KeysBridge]. Its pom.xml had only jjwt-api, the part of JJWT that code calls. The part that does the work, jjwt-impl, has to be there when the program runs.
What I Was Doing
I was writing small Java examples for JWT how-to posts. An earlier example of mine only encoded text with JJWT's Encoders, which needs nothing but the jjwt-api library, so its pom.xml listed only that one. I copied that pom.xml for a new example that creates a key and signs a token. The code compiled, and then the program stopped with the error below.
The example below shows the same thing with nothing else in the way: a program that signs a token with one claim.
What I Expected
The program to print a signed token.
What Happened Instead
Create a folder named demo, with this pom.xml in it:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jjwt.version>0.13.0</jjwt.version>
</properties>
<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jjwt.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
The only dependency is jjwt-api. The exec-maven-plugin entry names com.example.Main as the class to run.
Then the program, in src/main/java/com/example/Main.java:
package com.example;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import javax.crypto.SecretKey;
public class Main {
public static void main(String[] args) {
// The signing key: 32 random bytes, written as base64.
// It's in the code only for this example; a real app loads it from its configuration.
byte[] secret = Decoders.BASE64.decode("C4iNOOORzmu+fnrPK29yq/9n92b/zf5mOs5KvOMaY64=");
SecretKey key = Keys.hmacShaKeyFor(secret);
String token = Jwts.builder().subject("ada").signWith(key).compact();
System.out.println(token);
}
}
It decodes a base64 secret into bytes, turns them into a key with Keys.hmacShaKeyFor, and signs a token whose only claim is sub.
In the demo folder, build and run it:
mvn -q compile exec:java
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.7.0:java (default-cli) on project demo: An exception occurred while executing the Java class. null: ExceptionInInitializerError: Unable to load class named [io.jsonwebtoken.impl.security.KeysBridge] from the thread context, current, or system/application ClassLoaders. All heuristics have been exhausted. Class could not be found. Have you remembered to include the jjwt-impl.jar in your runtime classpath? -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

-q keeps Maven quiet, compile builds the program and exec:java runs it. The command is the same in zsh, bash and PowerShell. The program compiled, so the code itself was fine. It failed while running, with an ExceptionInInitializerError, before it printed anything.
What I Checked
- The message. It names a class,
io.jsonwebtoken.impl.security.KeysBridge, says that no class loader could find it, and ends with a question: "Have you remembered to include the jjwt-impl.jar in your runtime classpath?" - Where the classes live. Listing the two jars Maven downloaded,
jjwt-api-0.13.0.jarholdsJwtsandKeys, the classes the program calls, andjjwt-impl-0.13.0.jarholdsKeysBridge. That's why the program compiled: the compiler only needs the classes the code names. - The JJWT README. Its installation section lists three Maven dependencies:
jjwt-api, thenjjwt-implandjjwt-jackson, both with<scope>runtime</scope>. Understanding JJWT Dependencies explains: "Notice the above JJWT dependency declarations all have only one compile-time dependency and the rest are declared as runtime dependencies." It warns: "Never add thejjwt-impl.jar to your project withcompilescope - always declare it withruntimescope."
So the error was right: the pom.xml I copied was made for a program that never signs anything, and it left out the two parts JJWT needs at run time.
The Fix
Add jjwt-impl and jjwt-jackson to pom.xml, both with runtime scope, as the README lists them:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jjwt.version>0.13.0</jjwt.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- jjwt-jackson asks for Jackson 2.12.7.1. This makes Maven use the newest Jackson 2 instead. -->
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.23.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jjwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
jjwt-impldoes the work behindKeysandJwts,KeysBridgeincluded.jjwt-jacksonturns the token's header and claims into JSON with Jackson. The README namesjjwt-gsonas the choice for Gson.runtimescope, in the words of Maven's dependency scopes: "This scope indicates that the dependency is not required for compilation, but is for execution." Your code can't come to depend on JJWT's internal classes, because the compiler never sees them.- The
jackson-bomentry independencyManagementis separate from the error.jjwt-jacksonasks for Jackson 2.12.7.1, and this entry makes Maven use Jackson 2.23.0 instead, the newest Jackson 2 release.
The Result
Run it again:
mvn -q compile exec:java
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZGEifQ.atRrz4IWSoGBEf33EP2VKwwRNCz32yjpbjeoGLhOsdQ

The program printed a token signed with HS256, whose payload is {"sub":"ada"}.
How to Avoid It
- Start every JJWT project with all three dependencies:
jjwt-api, andjjwt-implandjjwt-jacksonwithruntimescope. - Don't take a
pom.xmlfrom a project that used less of a library. Check its dependencies against the library's installation instructions. - Read the question at the end of the message. JJWT names the missing jar there.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Unable to load class named [io.jsonwebtoken.impl.security.KeysBridge] | jjwt-impl isn't in pom.xml | Add it with runtime scope |
| The code compiles, but the program fails as soon as it calls JJWT | jjwt-impl isn't there when the program runs | Add it with runtime scope |
FAQ
Why does JJWT keep jjwt-impl out of compile scope?
So programs only use the parts that keep working across versions. The README: "JJWT guarantees semantic versioning compatibility for all of its artifacts except the jjwt-impl .jar."
Is the fix the same in Gradle?
The README lists the same three parts for Gradle, with jjwt-impl and jjwt-jackson as runtimeOnly dependencies. This post only ran the Maven build.
Conclusion
JJWT comes in three parts, and code compiles against only one of them, jjwt-api. When the program runs, jjwt-impl and jjwt-jackson must be there too, so list them in pom.xml with runtime scope.
Additional Resources
- Installation and Understanding JJWT Dependencies, in the JJWT README.
