Maven插件使用(复制,删除,打包,重命名文件等)

1、打包时复制文件到某位置

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-resources-plugin</artifactId>
   <executions>
      <execution>
         <id>copy-resources</id>
         <phase>prepare-package</phase>
         <goals>
            <goal>copy-resources</goal>
         </goals>
         <configuration>
            <encoding>UTF-8</encoding>
            <!--要复制到的路径-->
            <outputDirectory>
               ${project.build.directory}/configservice/WEB-INF/lib
            </outputDirectory>
            <resources>
               <resource>
                  <!--项目中文件的路径-->
                  <directory>target</directory>
               </resource>
            </resources>
            <overwrite>true</overwrite>
         </configuration>
      </execution>
   </executions>
</plugin>

2、打包时删除某些文件

<plugin>  
    <artifactId>maven-antrun-plugin</artifactId>  
    <executions>  
        <execution>  
            <phase>compile</phase>  
            <goals>  
                <goal>run</goal>  
            </goals>  
            <configuration>  
                <tasks>  
                    <delete file="${project.build.directory}/classes/jdbc.properties" />  
                    <move file="${project.build.directory}/classes/online_jdbc.properties" tofile="${project.build.directory}/classes/jdbc.properties"/>  
                </tasks>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>  

3、打包时重命名某文件

<!--${log.conf}读取profile下的属性值-->
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.8</version>
	<executions>
		<execution>
			<phase>compile</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<tasks>
					<move file="${project.build.directory}/classes/${log.conf}"
						  tofile="${project.build.directory}/classes/log4j.properties" />
				</tasks>
			</configuration>
		</execution>
	</executions>
</plugin>

4、打包时解压某压缩包或者jar/war包

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>prepare</id>
            <phase>validate</phase>
            <configuration>
                <tasks>
                    <echo message="prepare phase" />
                    <unzip src="zips/archive.zip" dest="output/" />
                    <unzip src="output/inner.zip" dest="output/" />
                    <unzip dest="output">
                      <fileset dir="archives">
                        <include name="prefix*.zip" />
                      </fileset>
                    </unzip>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独孤飞磊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值