java.lang.LinkageError: ClassCastException RuntimeDelegate.class

ぐ巨炮叔叔 提交于 2021-02-10 06:00:47

问题


I have this error

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

I'm using an open source wiki platform called xwiki https://github.com/xwiki/xwiki-platform

This platform somewhere include jsr311-api-1.1.1.jar and need it.

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>

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>

and so from org.keycloak.admin.client.Keycloak I call

Keycloak.getInstance(keycloakUrl, keycloakRealm, keycloakUser, keycloakPwd, "admin-cli");

And at this moment my running applicatiom ( because everything run well ) give me the ClassCastException above.

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 ?

Environment :

tomcat 9.0.12
XWiki 10.6.1
Keycloak 4.3.0
Java 8

回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/52278027/java-lang-linkageerror-classcastexception-runtimedelegate-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!