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