简体   繁体   English

Maven:如何保持依赖性?

[英]Maven: How To Keep A Dependency Out?

I'm new to Maven. 我是Maven的新手。 I recently learned it to solve some dependency issues I'm having with a Java and Spring WebApp. 我最近学到了它来解决我在Java和Spring WebApp上遇到的一些依赖问题。 I've been trying maven out on a small sample webapp. 我一直在尝试使用一个小样本webapp。 The webapp uses JSTL tags. webapp使用JSTL标记。 I found it necessary to put these tags in pom.xml: 我发现有必要将这些标签放在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: 这些我需要2个罐子:

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: 但它还包括我的WEB-INF / lib中的这个jar,当我尝试在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 ? 有没有办法可以重写我的依赖标记,将jsp-api-2.1.jar从我的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: FWIW,这就是我如何更改JSTL的依赖关系标签,而不是将JSP-API jar放在我的WEB-INF库中:

   <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 我能够在这个站点找到groupID和artifactID https://repository.sonatype.org/index.html#welcome

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. 找到哪一个,并添加排除部分。

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. 提供的作用域确保jar可供编译器使用,但假定在运行代码时将在运行时“提供”jar。 In your cast, it is provided by Tomcat. 在你的演员阵容中,它由Tomcat提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM