[英]maven 3 interproject depedency with war packaging
I have Eclipse Indigo and M2E plugin installed. 我安装了Eclipse Indigo和M2E插件。
So essentially I have a standard maven web project (let's call it proj-service) that is built into a war file in the package phase. 因此,从本质上讲,我有一个标准的Maven Web项目(简称为proj-service),该项目在打包阶段内置到war文件中。 This all works fine.
这一切都很好。 My issue comes in when I have my other project (lets call it proj1) that needs to use classes from proj-service.
当我有需要使用proj-service中的类的其他项目(称为proj1)时,就会出现我的问题。 I know that this is possible in maven+eclipse but it does not seem to be working at the moment.
我知道这在maven + eclipse中是可能的,但目前似乎无法正常工作。 I have the following in proj1's pom right now:
我现在在proj1的pom中具有以下内容:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj1</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>proj1</name>
<properties>
<spring.version>3.1.0.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Maven Repo Libraries -->
.........
<!-- Interproject dependencies -->
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>lsoap</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Unfortunately with Maven's war packaging you can't reuse classes from war project, because there is no direct build artifact you can use for the class path. 不幸的是,使用Maven的war打包,您不能重用war项目中的类,因为没有直接的构建工件可用于类路径。
So, in order to do share classes properly you need to extract those common classes into a 3rd common project (jar packaging) and make it as dependency in both of your other projects. 因此,为了正确共享类,您需要将这些公共类提取到第三个公共项目(jar包装)中,并使其成为两个其他项目中的依赖项。
First you have to change the configuration of your proj-service project in the way to change the configuration of the maven-war-plugin: 首先,您必须以更改maven-war-plugin的配置的方式更改proj-service项目的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<archiveClasses>true</archiveClasses>
...
</configuration>
</plugin>
This will it make possible to use the classes from the proj-service project in other projects via the following dependencies: 这样就可以通过以下依赖关系在其他项目中使用proj-service项目中的类:
<dependency>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>myVersion</myVersion>
<classifier>classes</classifier>
</dependency>
This will result in changing your dependency from: 这将导致您的依赖关系从以下方面改变:
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
into: 成:
<dependency>
<groupId>com.mycompany.foo</groupId>
<artifactId>proj-service</artifactId>
<version>1.0</version>
<classifier>classes</classifier/>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.