javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation:when resolving i

That will happen when you include server-specific libraries of a different server make/version in the/WEB-INF/lib of your web application, such as jsp-api.jarel-api.jarservlet-api.jar, etc. You need to remove them all. The /WEB-INF/lib should not contain any server-specific libraries. They belongs in the specific server itself (Tomcat has them in its /lib folder already).

This is by the way a pretty common beginner's mistake whenever they encounter compilation errors on the JSP/Servlet API in their IDE project. This should have been solved differently, namely by integrating the server in the IDE and adding the server as "Target runtime" to the project.

问题是在项目的lib目录中包含 服务器类提供过jar  比如jsp-api.jarel-api.jarservlet-api.jar, 等等。

思路是排除冲突的jar包。

开发环境是idea  启动方式是tomcat8:run-war

<dependency>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat8-maven-plugin</artifactId>
  <version>3.0-r1756463</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

第一种

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>3.1.0</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>3.1.0</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

第一种处理方式不适用于我,换个思路,具体原因是工程pom.xml文件引用了与tomcat8-maven-plugin中冲突的jar包,既然排除工程的pom.xml中的冲突jar不行,  那就把tomcat8-maven-plugin中引用的复制到pom.xml中

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-servlet-api</artifactId>
  <version>8.0.14</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jsp-api</artifactId>
  <version>8.0.14</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper</artifactId>
  <version>8.0.14</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper-el</artifactId>
  <version>8.0.14</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper-el-api</artifactId>
  <version>8.0.14</version>
  <!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>
</dependency>

引起冲突大致这几种,重新引入到工程pom.xml文件中,覆盖tomcat8-maven-plugin中的引用,

设置<!--加入:编译时需要,运行时不需要-->
  <scope>provided</scope>

重新编译启动成功!具体问题就出在上述包冲突,不影响工作进度,根本原因不细究,感兴趣的同志可以研究。上述解决方案是基于真实开发环境,如有不同请耐心解决,希望解决思路对各位有用。

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值