情景描述: 项目console是一个web项目有多个模块,现在为这个项目新建一个模块build.console用来编译构建。 对console项目mvn clean package后生成war包不放在默认的target目录下面。而是放在编译模块build.console的dist目录下面。 初步解决方法: maven中更改target目录可以用子目录,但是只能是相对于当前项目的目录, 虽然也能将war包打到项目外的目录下面,但是console项目下会出现一个奇怪的很深的目录。所以不合适。 解决方案 使用maven-dependency-plugin插件,代码如下: org.apache.maven.plugins maven-dependency-plugin 2.8 copy-war package copy ${project.groupId} ${project.artifactId} ${project.version} ${project.packaging} ${dist.console.war.dir} *.war
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-war</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>${dist.console.war.dir}</outputDirectory>
<includes>
<include>*.war</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>