Maven: How to save a dependency?

I am new to Maven. I recently learned how to solve some of the dependency problems I have with Java and Spring WebApp. I tried maven on a small sample webapp. Webapp uses JSTL tags. I found it necessary to place these tags in the 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>

      

They get 2 jars that I need:

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

      

BUT this also includes this jar in my WEB-INF / lib, including which throws all sorts of errors when I try to run it in Tomcat 7:

jsp-api-2.1.jar

      

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

thank


Fixed. Thank you, guys. FWIW, this is how I changed the dependency tags for JSTL to not put the JSP-API 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 managed to find the groupID and artifactID on this site https://repository.sonatype.org/index.html#welcome

+3


source to share


2 answers


There is an exception 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 you don't need. Find it and add an exclusion section.

+4


source


Change the area 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 the jar is available to the compiler, but assumes that it will be "provided" at runtime when the code is run. In your throw it is provided by Tomcat.

+1


source







All Articles