1. 程式人生 > >【圖文】關於maven自定義路徑打包方法

【圖文】關於maven自定義路徑打包方法

有興趣可以瞭解下這款國內人氣很旺的JAVA程式碼生成器基於拖拽,不用寫複雜的模板,支援多種資料庫,適配wap,管理後臺各種功能全有 免費開源 地址:https://blog.csdn.net/adyuebanwan/article/details/83006405 或者 http://www.magicalcoder.com

=======================================================================================

下面的圖是web模組的部分截圖 我想打包的是 test環境 就用definedpackage裡面的test目錄替換 

release環境的 同理用release目錄替換

使用maven-assembly-plugin外掛

1 開啟web模組的pom.xml

增加內容

<build>
<finalName>shumi-webtask</finalName>
<plugins>
<plugin>
   <artifactId>maven-assembly-plugin</artifactId>
<executions>  <!--執行器 mvn assembly:assembly-->
<execution>
<id>make-zip</id><!--名字任意 -->  
<phase>package</phase><!-- 繫結到package生命週期階段上 -->  
<goals>  
  <goal>single</goal><!-- 只執行一次 -->  
</goals>  
<configuration>
<descriptors> <!--描述檔案路徑  配置多個 就一起打出包了-->
 <!-- 釋出環境打包 -->
 <descriptor>definedpackage/release/zip.xml</descriptor>
 <!-- 測試環境打包 -->
 <descriptor>definedpackage/test/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

2 release/zip.xml內容

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>test</id>
<!-- 釋出環境打包 -->
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}\target\classes</directory><!-- 這裡你也可以寫絕對路徑-->
<excludes>
<!-- 忽略這些已經存在release中的檔案否則release就不能替換了 -->
<exclude>${project.basedir}\jdbc.properties</exclude>
<exclude>${project.basedir}\spring\spring-base.xml</exclude>
<exclude>${project.basedir}\mongo-jdbc.properties</exclude>
<exclude>${project.basedir}\zip.xml</exclude>
</excludes>
<outputDirectory>WEB-INF/classes</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\definedpackage\release</directory>
<excludes>
<!-- zip.xml是不需要的  -->
<exclude>${project.basedir}\zip.xml</exclude>
</excludes>
<outputDirectory>WEB-INF/classes</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\src\main\webapp</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<!-- jar包打出-->
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>WEB-INF/lib</outputDirectory>
<excludes>
<exclude>*:war</exclude><!-- 忽略war包 否則你會發現壓縮包中多了個war包 真是不智慧-->
</excludes>
<scope>runtime</scope><!-- 所有jar scope型別為runtime -->
</dependencySet>
</dependencySets>
 
</assembly>

3 test/zip.xml

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>test</id>
<!-- 釋出環境打包 -->
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}\target\classes</directory>
<excludes>
<!-- 忽略這些已經存在release中的檔案否則release就不能替換了 -->
<exclude>${project.basedir}\jdbc.properties</exclude>
<exclude>${project.basedir}\spring\spring-base.xml</exclude>
<exclude>${project.basedir}\mongo-jdbc.properties</exclude>
<exclude>${project.basedir}\zip.xml</exclude>
</excludes>
<outputDirectory>WEB-INF/classes</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\definedpackage\test</directory>
<excludes>
<!-- zip.xml是不需要的  -->
<exclude>${project.basedir}\zip.xml</exclude>
</excludes>
<outputDirectory>WEB-INF/classes</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.basedir}\src\main\webapp</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<!-- jar包打出-->
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>WEB-INF/lib</outputDirectory>
<excludes>
<exclude>*:war</exclude><!-- 忽略war包 -->
</excludes>
<scope>runtime</scope><!-- 所有jar scope型別為runtime -->
</dependencySet>
</dependencySets>
 
</assembly>

4 mvn clean package命令執行 清理並打包 一切ok