java.lang.LinkageError: ClassCastException

前端 未结 3 2049
-上瘾入骨i
-上瘾入骨i 2020-12-19 00:59

I do experience a really annoying problem with TestNG and RESTeasy.

I do have a class that runs several tests against an API class which uses the RESTeasy framework

相关标签:
3条回答
  • 2020-12-19 01:23

    I solved this problem by changing org.glassfish.jersey version in my pom.xml

    Below is my pom.xml

     <dependency>
          <groupId>javax.ws.rs</groupId>
          <artifactId>javax.ws.rs-api</artifactId>
          <version>2.1.1</version>
     </dependency>
     <dependency>
          <groupId>org.glassfish.jersey.core</groupId>
          <artifactId>jersey-client</artifactId>
          <version>2.31</version>
     </dependency>
    
    0 讨论(0)
  • 2020-12-19 01:38

    Unfortunately I can't tell you why this happened, but I can tell you how to get around this issue.

    The problem was, that PowerMockito scanned tha class path and also added the RESTeasy classes (which are located within the package 'javax.ws.*'. Therefor the above mentioned RuntimeDelegate was loaded by the PowerMockito classloader and caused later the issue, that the class was compared against one from a different classloader.

    To get around this issue, tell PowerMockito to ignore the javax.ws package when scanning for classes:

    @PowerMockIgnore({"javax.ws.*"})
    
    0 讨论(0)
  • 2020-12-19 01:47

    I faced the same issue when deploying my application to JBoss v6.1 - somehow understood that the problem was due to the same package structure of RuntimeDelegate.class existing within jesrey-core and jboss' jaxrs-api jar

    Below is my pom.xml

        <!-- For Restful Client -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.8</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>resteasy-jaxrs</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
        <!-- For Jackson (JSON Utility) -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.8.5</version>
        </dependency>
    
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.9</version>
             <exclusions>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    

    After my war is deployed to JBoss, just removed resteasy.deployer folder from jboss' server\default\deployers folder. Ran my application and it worked.

    I would be happy if someone explain why this error got resolved this way? (I think JBoss' has unnecessarily shipped with resteasy.deployers jars when developers could include the jars on their own in their apps) - Not to hide that I tried deploying my war on Tomcat and it worked smoothly.

    0 讨论(0)
提交回复
热议问题