Maven pom.xml 中导入jstl依赖
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
出现三个错误:
- Description Location Resource Path TypeMissing artifact javax.servlet.jsp.jstl:jstl:jar:1.2 line 69 pom.xml Maven Dependency Problem
- The container 'Maven Dependencies' references non existing library 'E:\Maven\Maven-Repository\javax\servlet\jsp\jstl\jstl\1.2\jstl-1.2.jar' Build path Build Path Problem
- The project cannot be built until build path errors are resolved Unknown Java Problem
Description Location Resource Path Type
Missing artifact javax.servlet.jsp.jstl:jstl:jar:1.2 line 69 pom.xml /ssm-crud Maven Dependency Problem
看第一个提示没看出理由,看第二个知道是jar包冲突,检查项目后未发现jar包有问题,通过网上资料查阅后发现问题是在tomcat中已有jsp-api和servlet-api,但maven下载jstl时也会把它所依赖的这两个包下载下来,所以就有了包冲突,因此在maven的pom.xml中需要排除这两个包的下载
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
它是把jstl的jar包给你完完整整地下下来了,可是竟然附带把jstl依赖的jar包像servlet-api.jar、jsp-api.jar一并下下来了!!!那么问题来了,对,你的项目里面大多数也需要用这两jar包,需要这两jar包,但是你知道接下来恐怖的是什么吗?我不知道大家用的中间件版本的兼容性咋样,反正我的tomcat里面的这两包就是与我项目里通过maven下下来的包冲突!!!
解决方法:
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
</exclusion>
</exclusions>
</dependency>