I'm creating a Keycloak extension with dependencies. I added the entry on the pom.xml
like this:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
Then I deployed it to Keycloak:
mvn clean install wildfly:deploy
But when I run it, I got the error:
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: org/json/JSONObject
Caused by: java.lang.NoClassDefFoundError: org/json/JSONObject
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject from [Module "deployment.keycloak-authenticator.jar" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
... 66 more
How to add dependencies to extensions in Keycloak?
You have to create your SPI dependencies as jboss modules.
Steps:
Add a jboss-deployment-structure.xml file in src/main/resources/META-INF directory or your SPI with something like this (oficial documentation):
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.json.json" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Make $KEYCLOAK_HOME/modules/system/layers/base/org/json/json/main directory
Add json-20160810.jar in created dir
Add a module.xml file in same dir with this content:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="org.json.json">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="json-20160810.jar"/>
</resources>
<dependencies>
</dependencies>
</module>
Compile your SPI
Restart keycloak
Redeploy your SPI
There is a better way, deploy as a EAR archive. This project shows how to: https://github.com/stianst/keycloak-experimental/tree/master/fido-u2f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With