4

My setup: jdk 7, Tomcat 7.0.29, ,Eclipse Juno (with m2e[Maven 3.0.4 embedded], m2eclipse-wtp)

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>

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

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

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.

Questions:

  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?
betomontejo
  • 1,657
  • 14
  • 26

2 Answers2

2

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>
ams
  • 60,316
  • 68
  • 200
  • 288
  • I am interested in 1.2.1 - this was adding jstl-api as a transitive dependency - which added jsp-api. See my solution here: http://stackoverflow.com/a/24468573/281545 – Mr_and_Mrs_D Jun 28 '14 at 16:01
  • Also your answer reminds me of: http://www.murraywilliams.com/2011/11/running-jstl-1-2-on-tomcat-7-using-maven/ – Mr_and_Mrs_D Jun 28 '14 at 16:46
1

For version 1.2.1 use:

<!-- add the selvlet-api that tomcat provides as provided -->
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>javax.servlet.jsp.jstl-api</artifactId>
    <version>1.2.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.1</version>
    <exclusions>
         <!-- jstl-api was adding selvlet-api 2.5 and jsp-api-->
        <exclusion>
            <artifactId>jstl-api</artifactId>
            <groupId>javax.servlet.jsp.jstl</groupId>
        </exclusion>
    </exclusions>
</dependency>

Because if not the jstl-api 1.2 will be added as a dependency. It is the jstl-api that added the jsp-api and servlet-api dependencies.

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361