使用maven-assembly-plugin将第三方依赖jar包 打包入jar

  • Post author:
  • Post category:其他



一、maven-assembly-plugin使用描述

The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.  (

maven-assembly-plugin 主页


目前它只有一个有意义的goal

, 详细的请看(

http://maven.apache.org/plugins/maven-assembly-plugin/plugin-info.html

):


Goal Description:


assembly:single
Assemble an application bundle or distribution from an assembly descriptor. This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).

single操作有很多可配置的参数,详细的请看(

http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html

)。

简单的说,

maven-assembly-plugin

就是用来帮助打包用的,比如说打出一个什么类型的包,包里包括哪些内容等等。

目前至少支持以下打包类型:

  • zip
  • tar
  • tar.gz
  • tar.bz2
  • jar
  • dir
  • war

默认情况下,打jar包时,只有在类路径上的文件资源会被打包到jar中,并且文件名是${artifactId}-${version}.jar


二、怎么用maven-assembly-plugin插件来定制化打包


1.首先需要添加插件声明:

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-assembly-plugin</artifactId>  
    <version>2.4</version>  
    <executions>  
        <execution>  
            <phase>package</phase>