老鬼的博客 来都来啦,那就随便看看吧~
Maven插件使用(复制,删除,打包,重命名文件等)
发布于: 2020-12-24 更新于: 2020-12-24 分类于:  阅读次数: 

一:打包时复制文件到某位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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>

二:打包时删除某些文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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>

三:打包时重命名某文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--${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>

四:打包时解压某压缩包或者jar/war包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<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>
*************感谢您的阅读*************