You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Keycloak添加外部SPI时出现org/json/JSONException类找不到错误

解决Keycloak SPI的java.lang.NoClassDefFoundError: org/json/JSONException问题

问题原因

你的Maven Shade插件配置中,对org.json依赖的匹配规则不完整——仅指定了groupId,缺少artifactId,导致打包时没有将org.json:json的类文件合并到最终的SPI jar包中,Keycloak运行时无法找到对应的类。

修复步骤

  1. 修改pom.xml中的Shade插件配置
    将原配置里的<include>org.json</include>替换为完整的依赖坐标<include>org.json:json</include>,确保Shade插件能正确识别并打包该依赖。修改后的Shade插件配置如下:

    <plugin>
      <artifactId>maven-shade-plugin</artifactId>
      <version>${maven.shade.version}</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <artifactSet>
              <includes>
                <include>software.amazon.awssdk:*</include>
                <include>org.reactivestreams:reactive-streams</include>
                <include>org.json:json</include>
              </includes>
            </artifactSet>
          </configuration>
        </execution>
      </executions>
    </plugin>
    
  2. 重新构建并验证

    • 执行命令重新打包:
      mvn clean package
      
    • 检查生成的jar包,确认org/json目录下的类已被包含:
      jar tf target/dasniko.keycloak-2fa-sms-authenticator.jar | grep org/json
      
      若输出包含org/json/JSONException.class等相关类,则说明打包正确。
  3. 更新Keycloak中的SPI插件
    将新生成的jar文件替换到Keycloak的providers目录下,重启Keycloak服务即可。

内容的提问来源于stack exchange,提问作者GurbaniX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 13:15:20