问题描述
我的设置:jdk 7,Tomcat 7.0.29,Eclipse Juno(带有m2e [Maven 3.0.4嵌入式],m2eclipse-wtp)
My setup: jdk 7, Tomcat 7.0.29, ,Eclipse Juno (with m2e[Maven 3.0.4 embedded], m2eclipse-wtp)
我有一个动态Web项目,具有以下 JSTL 依赖项:
I have a Dynamic Web Project with this JSTL dependency:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.1</version>
</dependency>
当我mvn package
并在Tomcat上部署时,我在日志中收到了这些非致命消息,这些消息不会阻止我的应用程序部署:
When I mvn package
and deploy on Tomcat, I get these non-fatal messages in the log that don't stop my app from deploying:
validateJarFile(...\WEB-INF\lib\jsp-api-2.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
validateJarFile(...\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
我检查了,是的,有问题的JAR正在打包在WAR中.我用mvn dependency:tree
检查依赖项并得到:
I check and yes, JARs in question are being packaged in the WAR. I check the dependencies with mvn dependency:tree
and get this:
[INFO] \- org.glassfish.web:javax.servlet.jsp.jstl:jar:1.2.1:compile
[INFO] \- javax.servlet.jsp.jstl:jstl-api:jar:1.2:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] \- javax.servlet.jsp:jsp-api:jar:2.1:compile
两个JAR都显示在compile
范围内,但是如果我检查我看到了:
Both JARs are showing in the compile
scope, But if I check the pom.xml on org.glassfish.web:javax.servlet.jsp.jstl:jar:1.2.1
I see this:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
将它们显示在provided
范围内,我认为可以将它们从包装中排除.
that shows them on the provided
scope, which I thought would exclude them from the packaging.
问题:
- 如何告诉WAR插件不包含这些JAR?
<excludes/>
不会删除它,因为这也会将它们从构建路径中删除. - 如果我想针对Servlet 3.0规范进行开发但保留此JSTL版本怎么办?
- How do I tell the WAR plugin to not include these JAR's?
<excludes/>
won't cut it because this also removes them from the build path. - What if I want to develop against the Servlet 3.0 spec but keeping this JSTL version?
推荐答案
弄清楚了,jsp-api作为jstl的过渡依赖项潜入WEB-INF \ lib,解决方法是排除这种情况.
Figured it out, the jsp-api was sneaking into the WEB-INF\lib as a transative dependency of the jstl, the fix is to exclude like so.
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>${javax.jstl.version}</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<artifactId>jsp-api</artifactId>
<groupId>javax.servlet.jsp</groupId>
</exclusion>
</exclusions>
</dependency>
这篇关于修复了Maven JSTL 1.2.1依赖性,因此maven-war-plugin不会打包冒犯Tomcat 7的JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!