使用assembly plugin实现自定义打包
在上一篇文章中,讨论到在对maven的机制不熟悉的情况下,为了实现自己需要的打包格式而使用maven ant task以maven + ant的方式来实现非标准打包,而现在要介绍的是maven中针对打包任务而提供的标准插件:assembly plugin。
依然以上文(初学maven(4)-使用maven ant task实现非标准打包)的项目为例,要打包的程序如下:
demo1 |____lib |_____demo1.jar |_____*****.jar |_____*****.jar |____config |_____*****.properties |_____*****.xml |____log |_____*****.log |____run.bat |____run.sh
demo1 |____src/main/java |____src/main/config |____src/main/bin |____src/main/resources |____src/main/assemble |____src/test/java |____src/test/resources |____target |____pom.xml
<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <!-- not append assembly id in release file name --> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assemble/package.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd"> <id>package</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> </fileSet> <fileSet> <directory>src/main/config</directory> <outputDirectory>config</outputDirectory> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> </dependencySet> </dependencySets></assembly>
<fileSet> <directory>src/main/bin</directory> <outputDirectory>/</outputDirectory> </fileSet>
fileSet> <directory>src/main/config</directory> <outputDirectory>config</outputDirectory></fileSet>
<dependencySet> <outputDirectory>lib</outputDirectory> <scope>runtime</scope> </dependencySet>