关于maven自定义路径打包方法

下面的图是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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值