maven如何打包成zip
pom.xml插件添加
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.1</version> <configuration> <descriptors> <descriptor>src/main/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <!--this is used for inheritance merges 绑定到这个生命周期--> <goals> <goal>single</goal> <!--执行一次--> </goals> </execution> </executions> </plugin>
assembly.xml文件添加
<assembly> <id>1.0</id> <formats> <!--支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war--> <format>zip</format> </formats> <dependencySets> <!-- 用来定制工程依赖 jar 包的打包方式,依赖包的输出路径 --> <dependencySet> <outputDirectory>/libs</outputDirectory> <!--依赖jar包的输出目录--> <useProjectArtifact>false</useProjectArtifact> <includes> <!--指定把哪些依赖包放进去 --> <!--如果不指定 则所有的依赖都会打入,但是有的时候 我们只需要打特定依赖的包--> <include>net.sf.jsi:jsi</include> <include>net.sf.trove4j:trove4j</include> </includes> </dependencySet> </dependencySets> <includeBaseDirectory>true</includeBaseDirectory> <fileSets><!--这里指定需要包含的其他文件--> <fileSet> <!--管理一组文件的存放位置--> <outputDirectory>/</outputDirectory> <!--放在哪--> <directory>target</directory><!--源目录--> <includes> <include>*.jar</include> <!--代码的jar包--> </includes> <excludes> <exclude>*sources.jar</exclude> </excludes> </fileSet> <fileSet> <directory>src\main\resources</directory> <!--配置文件源目录--> <outputDirectory>config</outputDirectory> </fileSet> <fileSet> <outputDirectory>/shell</outputDirectory> <directory>src/main/resources/shell</directory> <includes> <include>*/*.sh</include> <!--把shell脚本打进去--> <include>*/*.conf</include> <!--把conf文件打进去--> </includes> </fileSet> </fileSets> </assembly>
结果展示
![](https://i-blog.csdnimg.cn/blog_migrate/19859f9ddfdcd8c01fc2ff0e8cce2d61.png)