本文介绍了修复了Maven JSTL 1.2.1依赖性,因此maven-war-plugin不会打包冒犯Tomcat 7的JAR.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置: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软件包并在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中.我用 mvndependency: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 范围内,但是如果我检查.servlet.jsp.jstl:jar:1.2.1 我看到了:

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>

将它们显示在提供的范围内,我认为这会将它们从包装中排除.

that shows them on the provided scope, which I thought would exclude them from the packaging.

问题:

  1. 如何告诉WAR插件不包含这些JAR?< excludes/> 不会删除它,因为这也会将它们从构建路径中删除.
  2. 如果我想针对Servlet 3.0规范进行开发但保留此JSTL版本怎么办?
  1. 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.
  2. 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.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:46