【发布时间】:2015-07-15 19:33:46
【问题描述】:
我有一个 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>
【问题讨论】:
-
从 pom.xml 中简单地删除
<optional>true</optional>。如果您希望commons-dbcp需要添加到WEB-INF/lib 中,则不要将其标记为<optional>。所以删除<optional>并添加<version> -
看看“可选依赖项如何工作?”此链接中的部分maven.apache.org/guides/introduction/…。它说“当 A 在其 POM 中将 B 声明为可选依赖项时,这种关系保持不变。就像在其类路径中添加 Project-B 的正常构建一样。”。注意:我需要将可选设置为 true 因为这是一个 ejb 模块并且是对其他模块的依赖。其他模块不需要ejb模块的依赖。他们所需要的只是它的 ejb 客户端。
-
在coderanch.com/t/531050/tools/… 问题中,
true 正在做它应该做的事情。他添加了 spring-core 作为依赖项,并且在 spring-core 中声明的可选依赖项没有包含在他的项目中,这正是可选依赖项应该做的。因为这些可选依赖项仅适用于 spring-core 项目。因此,后来引用了 maven doc 中的一段话:“如果用户想要使用与可选依赖项相关的功能,他们将不得不在自己的项目中重新声明该可选依赖项。”
标签: maven-3