Steve
Steve

Reputation: 2816

Maven: How To Keep A Dependency Out?

I'm new to Maven. I recently learned it to solve some dependency issues I'm having with a Java and Spring WebApp. I've been trying maven out on a small sample webapp. The webapp uses JSTL tags. I found it necessary to put these tags in pom.xml:

   <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2-rev-1</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
    </dependency>

These get 2 jars that I need:

jstl-api-1.2-rev-1.jar
jstl-impl-1.2.jar

BUT it also includes THIS jar in my WEB-INF/lib, the inclusion of which causes all sorts of errors when I try to run it in Tomcat 7:

jsp-api-2.1.jar

Is there a way I can rewrite my dependency tags to leave jsp-api-2.1.jar out of my WEB-INF/lib ?

Thanks


Fixed. Thanks Guys. FWIW, this is how I changed the dependency tags for the JSTL to not put the JSP-API jar in my WEB-INF lib:

   <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2-rev-1</version>
        <exclusions>
            <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.jsp</groupId>
                <artifactId>jsp-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

I was able to find the groupID and artifactID at this site https://repository.sonatype.org/index.html#welcome

Upvotes: 3

Views: 446

Answers (2)

Virtually Real
Virtually Real

Reputation: 1685

Have exclusions section, similar to the one below.

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate</artifactId>
  <version>3.2.6.ga</version>
  <exclusions>
    <exclusion>
      <groupId>javax.transaction</groupId>
      <artifactId>jta</artifactId>
    </exclusion>
  </exclusions>
</dependency>

In your case, one (or both) of the dependencies you add include the one that you do not need. Find which one, and add the exclusion section.

Upvotes: 4

Roy Truelove
Roy Truelove

Reputation: 22456

Change the scope to 'provided'. EG:

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jstl-impl</artifactId>
    <version>1.2</version>
    <scope>provided</scope>
</dependency>

The provided scope ensures that jar is available to the compiler, but assumes that it will be 'provided' at runtime when the code is run. In your cast, it is provided by Tomcat.

Upvotes: 1

Related Questions