我正在使用Maven 3构建3层的java应用程序 - 服务器,ejb和ui。 EJB项目依赖于Server项目,并且UI项目仅依赖于EJB,并为Server传递依赖项提供排除。Maven构建与依赖树不同
当UI项目构建为一个war时,虽然服务器依赖项没有显示在dependency:tree命令上,但仍包含在其中。
这里是运行mvn dependency:tree
**project.name:UI:war:1.0 SNAPSHOT**
+- project.name:Common:jar:1.0 SNAPSHOT:compile
| + org_common:_lib:jar:16.0.006:compile
| | +- log4j:log4j:jar:1.2.16:compile
| | \- commons configuration:commons configuration:jar:1.6:compile
| | +- commons lang:commons lang:jar:2.4:compile
| | +- commons digester:commons digester:jar:1.8:compile
| | \- commons beanutils:commons beanutils core:jar:1.8.0:compile
| +- org_common:_security_lib:jar:16.0.006:compile
| \- org.springframework:spring:jar:2.0:compile
+- **project.name:EJB:ejb client:client:1.0 SNAPSHOT:compile**
| \- com.ibm.websphere.appserver:j2ee:jar:7.0.0.9:compile
+- org_common:_uicomponent:jar:16.0.006:compile
的相关输出而这里是运行mvn clean install -X
**project.name:UI:war:1.0 SNAPSHOT**
+- project.name:Common:jar:1.0 SNAPSHOT:compile
| + org_common:_lib:jar:16.0.006:compile
| | +- log4j:log4j:jar:1.2.16:compile
| | \- commons configuration:commons configuration:jar:1.6:compile
| | +- commons lang:commons lang:jar:2.4:compile
| | +- commons digester:commons digester:jar:1.8:compile
| | \- commons beanutils:commons beanutils core:jar:1.8.0:compile
| +- org_common:_security_lib:jar:16.0.006:compile
| \- org.springframework:spring:jar:2.0:compile
+- **project.name:EJB:ejb client:client:1.0 SNAPSHOT:compile**
| +- **project.name:Server:jar:1.0 SNAPSHOT:compile**
| | +- javassist:javassist:jar:3.4.GA:compile
| | +- project.filestore:filestore_client:jar:7.0.003:compile
| | +- com.ibm.db2:db2jcc:jar:9.7.fp1.aix64.s091114:compile
| | +- com.ibm.db2:db2java:jar:9.7.fp1.aix64.s091114:compile
| | +- com.ibm.db2:db2jcc_license_cu:jar:9.7.fp1.aix64.s091114:compile
| \- com.ibm.websphere.appserver:j2ee:jar:7.0.0.9:compile
+- org_common:_uicomponent:jar:16.0.006:compile
当服务器上的依赖是两两棵树之间的唯一区别输出依赖关系树。 这两个输出不应该总是一样吗?什么可能导致图书馆被列入依赖:树?
父POM模块定义为:
<modules>
<module>Server</module>
<module>EJB</module>
<module>UI</module>
</modules>
在EJB POM列出的依赖关系是:
<dependencies>
<dependency>
<groupId>project.name</groupId>
<artifactId>Server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
在用户界面中的相关性是:
<dependencies>
<dependency>
<groupId>project.name</groupId>
<artifactId>EJB</artifactId>
<version>${project.version}</version>
<type>ejb-client</type>
<exclusions>
<exclusion>
<groupId>project.name</groupId>
<artifactId>Server</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
我我知道我可以明确地排除服务器jar包含在WAR中,但我更愿意修复actua升问题。
如果UI依赖于EJB并且EJB依赖于Server,那么UI取决于Server。因此,您可以通过将其范围设置为“provided”,从EJB-INF/lib中将它的传递依赖关系排除在EJB之外,或者将其全部打包为war。据我所知,没有任何方法可以在没有传递依赖的战争中只包含基础工件。 – 2012-04-05 06:12:09
您使用的是最新的依赖插件(2.4)吗? – khmarbaise 2012-04-05 07:49:34
@AndrewLogvinov这就是为什么当EJB项目作为UI的依赖添加时,我在服务器上进行排除。 EJB层在maven中很特别 - 它分为Client和Server jars - UI所依赖的客户机jar不依赖于Server。如果传递性依赖被明确排除,为什么会包含它? – 2012-04-09 22:59:14