将 JAX-RS 应用程序部署到 Tomcat 时出现 IncompatibleClassChangeError应用程序、RS、JAX、Tomcat

由网友(丿皇族灬爱恋丶)分享简介:当我在 Tomcat 8 上使用 JDK 8 从 Eclipse 运行我的 Web 项目时,一切正常,但是一旦我构建了这个项目并将 WAR 部署到服务器上的 Tomcat 8,我就会收到以下错误:When I am running my web project from Eclipse on Tomcat 8 wit...

当我在 Tomcat 8 上使用 JDK 8 从 Eclipse 运行我的 Web 项目时,一切正常,但是一旦我构建了这个项目并将 WAR 部署到服务器上的 Tomcat 8,我就会收到以下错误:

When I am running my web project from Eclipse on Tomcat 8 with JDK 8 everything works flawlessly, but once I build this project and deploy the WAR to Tomcat 8 on the server I get the following error:

java.lang.IncompatibleClassChangeError: com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider and com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$Wadl disagree on InnerClasses attribute

我已经尝试了所有方法,但仍然无法正常工作.

I've tried everything, but it's still not working.

这是我的 pom.xml 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RestWebService</groupId>
<artifactId>RestWebService</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <warSourceDirectory>WebContent</warSourceDirectory>
      <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
  </plugin>
</plugins>
 </build>

<dependencies>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20140107</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.5</version>
    </dependency>
            <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.17.1</version>
    </dependency>
</dependencies>
</project>

这里是项目中所有 JAR 文件的列表:

Here is the list of all JAR files in the project:

asm-3.3.1.jar
jersey-bundle-1.19.jar
jsr311-api-1.1.1.jar
json-20140107.jar
jersey-server-1.19.jar
jersey-core-1.19.jar
gson-2.5.jar
sqljdbc4-4.0.jar
jersey-json-1.17.1.jar
jettison-1.1.jar
jaxb-impl-2.2.3-1.jar
jaxb-api-2.2.2.jar
stax-api-1.0-2.jar
activation-1.1.jar
jackson-core-asl-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-xc-1.9.2.jar

推荐答案

貌似是依赖版本的问题

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.17.1</version>
</dependency>

以上内容应与您的所有其他 Jersey 依赖项匹配相同的版本.所以只需将其更改为 1.19.

The above should match the same version as all your other Jersey dependencies. So just change it to 1.19.

阅读全文

相关推荐

最新文章