情景描述: 項目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} *.warweb
<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>