java.lang.LinkageError:ClassCastException RuntimeDelegate.class [英] java.lang.LinkageError: ClassCastException RuntimeDelegate.class
问题描述
我遇到此错误
java.lang.LinkageError: ClassCastException: attempting to tomcat-debug-eclispe/wtpwebapps/xwiki-debug-eclipse/WEB-INF/lib/jsr311-api-1.1.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to tomcat-debug-eclispe/lib/jboss-jaxrs-api_2.0_spec-1.0.1.Final.jar!/javax/ws/rs/ext/RuntimeDelegate.class
我正在使用一个名为xwiki
的开源Wiki平台.
https://github.com/xwiki/xwiki-platform
I'm using an open source wiki platform called xwiki
https://github.com/xwiki/xwiki-platform
该平台包含jsr311-api-1.1.1.jar
并且需要它.
This platform somewhere include jsr311-api-1.1.1.jar
and need it.
现在,我想通过XWiki扩展程序连接某些密钥隐藏功能,而我需要
Now I want to connect through an XWiki Extension some keycloak feature and I need this
<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-admin-client -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>4.3.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-admin-client -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>4.3.0.Final</version>
</dependency>
我们可以在此处 keycloak-admin-client需要一些提供的依赖项,包括:
As we can see here keycloak-admin-client need some provided dependencies including :
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
<version>1.0.1.Final</version>
<scope>provided</scope>
</dependency>
,所以从org.keycloak.admin.client.Keycloak
我打
Keycloak.getInstance(keycloakUrl, keycloakRealm, keycloakUser, keycloakPwd, "admin-cli");
这时我正在运行的应用程序(因为一切运行良好)给了我上面的ClassCastException
.
And at this moment my running applicatiom ( because everything run well ) give me the ClassCastException
above.
这里更是一个全球性的Jave(JEE)问题,我不能再提供更多代码,因为最后您将无法构建XWiki/Keycloak运行环境并重现该问题(因为在eclipse中,通过单位测试,在xwiki环境之外没有冲突,并且Keycloak.getInstance
可以正常工作).
It's more a global jave ( JEE ) question here, I can't give more code 'cause at the end you won t be able to build an XWiki/Keycloak running environment and reproduce the issue ( because in eclipse, throught unit test, outside the xwiki environment there is ofc no conflict and Keycloak.getInstance
works fine ).
在这种情况下我该怎么办?有没有一种避免这些冲突的行之有效的方法?也许需要重新实现的课程?
what can I do in this situation ? is there a maven way to avoid theses conflict ? maybe a class to reimplement ?
环境:
tomcat 9.0.12
XWiki 10.6.1
Keycloak 4.3.0
Java 8
推荐答案
之所以嵌入jsr311-api而不是仅仅作为提供的作用域依赖项,是因为Java 9中不再包含JAX-RS API(在Java 8),这对于各种应用程序服务器都是个问题(没有注意到Tomcat 9决定提供JAX-RS API,但我想它应该支持Java 9).参见 https://jira.xwiki.org/browse/XWIKI-14743 .
The reason why jsr311-api is embedded instead of just being a provided scope dependency is because JAX-RS API is not included in Java 9 anymore (it was in Java 8) and it was a problem for various application servers (did not noticed Tomcat 9 had decided to provide JAX-RS API but I guess it was to support Java 9). See https://jira.xwiki.org/browse/XWIKI-14743.
现在,XWiki仍然基于(非常古老的)JAX-RS 1的原因是Restlet基于JAX-RS 1,而JAX-RS 2的兼容性较差,因此当您使用XWiki时,会遇到各种问题.尝试使用它运行Restlet.
Now the reason why XWiki is still based on (the very old) JAX-RS 1 is that Restlet is based on JAX-RS 1 and JAX-RS 2 is not so great with retro compatibility so there is various problems when you try to run Restlet with it.
如果将Tomcat 9更改为Tomcat 8,则不会再出现启动错误.不幸的是,如果密钥斗篷需要JAX-RS 2,这将不容易.也许旧版本的keycloak是基于JAX-RS 1的,但是降级确实不是很好.我创建了 https://jira.xwiki.org/browse/XWIKI-15588 .
If you change Tomcat 9 for Tomcat 8 you won't have startup error anymore. Unfortunately if keycloak require JAX-RS 2 it's not going to be easy. Maybe an older version of keycloak is based on JAX-RS 1 but that's indeed not very nice to have to downgrade it. I created https://jira.xwiki.org/browse/XWIKI-15588.
这篇关于java.lang.LinkageError:ClassCastException RuntimeDelegate.class的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!