Unable to find an implementation for interface io.jsonwebtoken.io.Serializer ... in fat jar
See original GitHub issueHi guys,
We are seeing this error:
Unable to find an implementation for interface io.jsonwebtoken.io.Serializer using java.util.ServiceLoader. Ensure you include a backing implementation .jar in the classpath, for example, jjwt-impl.jar, or your own .jar for custom implementations.
Of course, we’ve included all deps:
implementation 'io.jsonwebtoken:jjwt-api:0.11.0'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.0'
implementation 'io.jsonwebtoken:jjwt-gson:0.11.0'
We are using a fat jar (all jars merged into one big jar). I’ve checked and the classes are present in our fat jar:
$ jar tf releases/server-1.20.42.jar | grep jsonwebtoken.*Serializer
io/jsonwebtoken/io/JacksonSerializer.class
io/jsonwebtoken/gson/io/GsonSerializer.class
io/jsonwebtoken/io/Serializer.class
There’s something I’m missing because this class is loaded using the standard ServiceLoader which says:
A service provider is identified by placing a provider-configuration file in the resource directory META-INF/services. The file’s name is the fully-qualified binary name of the service’s type.
Well, I can see any such file in the jjwt-gson:
$ mkdir temp; cd temp
$ jar xf ~/.gradle/caches/modules-2/files-2.1/io.jsonwebtoken/jjwt-gson/0.11.0/8042478d4d0024aa4edb0d608475093acfc7f3e8/jjwt-gson-0.11.0.jar
$ find -type f
./io/jsonwebtoken/gson/io/GsonSerializer.class
./io/jsonwebtoken/gson/io/GsonDeserializer.class
./META-INF/MANIFEST.MF
./META-INF/maven/io.jsonwebtoken/jjwt-gson/pom.xml
./META-INF/maven/io.jsonwebtoken/jjwt-gson/pom.properties
So I’m not sure how this is supposed to work.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top GitHub Comments
Hi. I have same issue while working with war package. I have jjwt-impl-0.11.1.jar and jjwt-api-0.11.1.jar inside App-server-0.0.2-SNAPSHOT.war\WEB-INF\lib
But tomcat prints error:
04-Jun-2020 19:55:53.156 SEVERE [http-nio-9000-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.qiagen.qbase.qbap.server.conf.RestConfig] in context with path [] threw exception [io.jsonwebtoken.lang.UnknownClassException: Unable to find an implementation for interface io.jsonwebtoken.io.Serializer using java.util.ServiceLoader. Ensure you include a backing implementation .jar in the classpath, for example jjwt-impl.jar, or your own .jar for custom implementations.] with root cause io.jsonwebtoken.impl.lang.UnavailableImplementationException: Unable to find an implementation for interface io.jsonwebtoken.io.Serializer using java.util.ServiceLoader. Ensure you include a backing implementation .jar in the classpath, for example jjwt-impl.jar, or your own .jar for custom implementations. at io.jsonwebtoken.impl.lang.Services.loadFirst(Services.java:105) at io.jsonwebtoken.impl.lang.LegacyServices.loadFirst(LegacyServices.java:21) at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:300) at com.app.adapter.jwt.JwtAdapter.create(JwtAdapter.java:43)
UPDATE
Oh. Ive added:
and now it works.
Is a serializer JAR (for Jackson or Gson) required?
Like @mbogner said,
with 0.11.2 I’m also seeing this error unless I include the Jackson or Gson jar and the error message is misleading as it says that the
jjwt-impl.jar
is missing, but it’s actually thejjwt-jackson.jar
that was missing in my case:results in:
but this works: