我正在创建一个带有依赖项的Keycloak扩展。我在pom.xml
上添加了这样的条目:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
然后我将它部署到Keycloak:
mvn clean install wildfly:deploy
但是当我运行它时,我收到了错误:
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
如何在Keycloak中为扩展添加依赖项?
答案 0 :(得分:3)
你必须create your SPI dependencies as jboss modules。
步骤:
在src / main / resources / META-INF目录或您的SPI中添加一个jboss-deployment-structure.xml文件,如下所示(oficial documentation):
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.json.json" />
</dependencies>
</deployment>
</jboss-deployment-structure>
制作$ KEYCLOAK_HOME / modules / system / layers / base / org / json / json / main目录
使用以下内容在同一目录中添加module.xml文件:
<?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-javadoc.jar"/>
</resources>
<dependencies>
</dependencies>
</module>
编译您的SPI
答案 1 :(得分:0)
还有一种更好的方法,将其部署为EAR归档文件。该项目显示了如何:https://github.com/stianst/keycloak-experimental/tree/master/fido-u2f