maven打包插件maven-assembly-plugin
Posted pinezhang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven打包插件maven-assembly-plugin相关的知识,希望对你有一定的参考价值。
1.POM文件添加jar包生成插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
<!-- 是否指定项目classpath下的依赖 -->
<addClasspath>true</addClasspath>
<!-- 指定依赖的时候声明前缀 -->
<classpathPrefix>./lib/</classpathPrefix>
<!--依赖是否使用带有时间戳的唯一版本号,如:xxx-1.3.0-20121225.012733.jar-->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
2.添加第三方依赖打包插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
3.添加assembly打包插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<!-- 配置执行器 -->
<execution>
<id>make-assembly</id>
<phase>package</phase><!-- 绑定到package生命周期阶段上 -->
<goals>
<goal>single</goal><!-- 只运行一次 -->
</goals>
<configuration>
<finalName>${project.name}</finalName>
<!--配置描述文件路径-->
<descriptor>assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
4.添加打包描述文件assembly.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>dropwizard-package</id>
<!--打包格式-->
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!--导入指定文件到tar.gz包-->
<fileSet>
<directory>${project.basedir}/target</directory>
<outputDirectory>./${project.name}</outputDirectory>
<directoryMode>0775</directoryMode>
<fileMode>0775</fileMode>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/target/lib</directory>
<outputDirectory>./${project.name}/lib</outputDirectory>
<directoryMode>0775</directoryMode>
<fileMode>0775</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>./${project.name}/conf</outputDirectory>
<directoryMode>0775</directoryMode>
<fileMode>0775</fileMode>
</fileSet>
</fileSets>
</assembly>
5.Over!!!
以上是关于maven打包插件maven-assembly-plugin的主要内容,如果未能解决你的问题,请参考以下文章
Maven实战技巧「插件使用专题」Maven-Assembly插件实现自定义打包
maven项目打包插件:将maven项目打包成一个可执行的jar(瘦jar)