Maven - WEB-INF / lib中未包含的可选依赖项

时间:2015-07-15 19:33:46

标签: maven-3

我有一个maven war模块,它在pom.xml中声明了几个可选的依赖项。在eclipse中,那些选项依赖项显示为构建路径的一部分,这正是我所期望的。但是在打包war文件时,maven不包括WEB-INF / lib文件夹中的那些依赖项,根据maven doc:https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html这不正确。知道为什么会这样吗?

以下是完整的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>dhive</artifactId>
    <groupId>com.boss</groupId>
    <version>1.0</version>
</parent>

<artifactId>Boss</artifactId>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>uk.com.robust-it</groupId>
        <artifactId>cloning</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>net.sf.jt400</groupId>
        <artifactId>jt400</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc14</artifactId>
        <optional>true</optional>
    </dependency>       
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.qoppa</groupId>
      <artifactId>jPDFProcess</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>multivalent</artifactId>
        <optional>true</optional>
    </dependency>       
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>multivalentArch</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
      <groupId>org.jpedal</groupId>
      <artifactId>jpedal</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>invoiceTool</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
       <groupId>com.sun</groupId>
       <artifactId>tools</artifactId>
       <version>1.6.0</version>
       <scope>system</scope>
       <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
     </dependency>                  
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>BossClient</id>
                    <configuration>
                        <ejbVersion>3.1</ejbVersion>
                        <generateClient>true</generateClient>
                        <clientIncludes>
                            <clientInclude>/com/**</clientInclude>
                        </clientIncludes>
                    </configuration>
                    <goals>
                        <goal>ejb</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2 个答案:

答案 0 :(得分:0)

我想你需要在pom.xml中改变你plugin尝试添加以下插件

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
      </plugin>

答案 1 :(得分:0)

为此创建了一个Maven WAR插件问题https://issues.apache.org/jira/browse/MWAR-351

为了解决这个问题,我最终不得不删除

<optional>true</optional> 

从ejb war模块开始工作。对于需要来自此war模块的ejb-client的所有其他项目/模块,我最终必须进行排除以避免将其依赖项添加到这些项目/模块中(参见下文)。

  <dependency>
    <groupId>com.boss</groupId>
    <artifactId>Boss</artifactId>
    <version>1.0</version>
    <type>ejb-client</type>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>       
</dependency>