【MAVEN】打包插件

1. maven-jar-plugin

作用:打包(jar)插件,设定 MAINFEST .MF文件的参数,比如指定运行的Main class、将依赖的jar包加入classpath中等等,首先我们明确一点的是maven 插件功能:compile、package、deploy…都是在${project.build.directory }/classes 文件路径下,当然测试是在test-classes下

MANIFEST.MF文件详解

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <archive>                     <!-- 存档 -->
          <addMavenDescriptor/>       <!-- 添加maven 描述 -->
          <compress/>                 <!-- 压缩 -->
          <forced/> 
          <index/>
          <manifest>                            <!-- 配置清单(MANIFEST)-->
            <addClasspath/>                         <!-- 添加到classpath 开关 -->
            <addDefaultImplementationEntries/> 
            <addDefaultSpecificationEntries/>
            <addExtensions/>
            <classpathLayoutType/>
            <classpathMavenRepositoryLayout/>
            <classpathPrefix/>                      <!-- classpath 前缀 -->
            <customClasspathLayout/>
            <mainClass/>                            <!-- 程序主函数入口 -->
            <packageName/>                          <!-- 打包名称 -->
            <useUniqueVersions/>                    <!-- 使用唯一版本 -->
          </manifest>
          <manifestEntries>                     <!-- 配置清单(MANIFEST)属性 -->                       
            <key>value</key>
          </manifestEntries>
          <manifestFile/>                       <!-- MANIFEST 文件位置 -->
          <manifestSections>
            <manifestSection>
              <name/>
              <manifestEntries>
                <key>value</key>
              </manifestEntries>
            <manifestSection/>
          </manifestSections>
          <pomPropertiesFile/>
        </archive>
         
        <excludes>                          <!-- 过滤掉不希望包含在jar中的文件  --> 
            <exclude/>
        </excludes>  
        
        <includes>                          <!-- 添加文件到jar中的文件  --> 
            <include/>
        </includes>
    </configuration>  
</plugin>

最小化配置

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>  
        <archive>  
            <addMavenDescriptor>false</addMavenDescriptor>  
            <manifest>  
                <addClasspath>true</addClasspath>  
                <classpathPrefix>lib/</classpathPrefix>  
                <mainClass>com.meix.boot.Application</mainClass>  
            </manifest>
            <manifestEntries>  
                <Class-Path>./</Class-Path>  
            </manifestEntries> 
        </archive>  
         <!-- 过滤掉不希望包含在jar中的文件  -->  
        <excludes>  
            <exclude>*.xml</exclude>  
            <exclude>spring/**</exclude>  
            <exclude>config/**</exclude>  
        </excludes> 
        <!-- 这里不做举例了 -->
        <includes>
            <include></include>
        </includes>         
    </configuration>  
</plugin>

具体详情标签参照下文,其实也是直接从官网copy而已:

archive(档案):
ElementDescriptionTypeDefault
addMavenDescriptor创建的存档是否包含以下两个Maven文件:1、pom文件,位于 META-INF / maven / ${groupId} / ${artifactId}/pom.xml 2、pom.properties文件,位于META-INF / maven / ${groupId} / ${artifactId} /pom.propertiesbooleantrue
compress是否压缩booleantrue
forced是否强制重建存档booleantrue
index创建的存档是否包含 INDEX.LIST文件booleanfalse
manifest
manifestEntries要添加到清单的键/值对的列表Map
manifestFile提供自己的清单文件File
manifestSections
pomPropertiesFile使用此选项覆盖自动创建的 pom.properties文件(仅当addMavenDescriptor设置为true时)File
archive 一般按默认设置即可
manifest(清单):
ElementDescriptionTypeDefault
addClasspath是否创建Class-Path清单条目booleanfalse
addDefaultImplementationEntriesmanifest 将会包含以下内容:1.Implementation-Title: p r o j e c t . n a m e 2. I m p l e m e n t a t i o n − V e r s i o n : {project.name} 2.Implementation-Version: project.name2.ImplementationVersion:{project.version} 3.Implementation-Vendor-Id: ${project.groupId} 4.Implementation-Vendor: p r o j e c t . o r g a n i z a t i o n . n a m e 5. I m p l e m e n t a t i o n − U R L : {project.organization.name} 5.Implementation-URL: project.organization.name5.ImplementationURL:{project.url}booleanfalse
addDefaultSpecificationEntriesmanifest 将会包含以下内容:1.Specification-Title: ${project.name} 2.Specification-Version: p r o j e c t . a r t i f a c t . s e l e c t e d V e r s i o n . m a j o r V e r s i o n 3. {project.artifact.selectedVersion.majorVersion} 3. project.artifact.selectedVersion.majorVersion3.{project.artifact.selectedVersion.minorVersion} Specification-Vendor: ${project.organization.name}booleanfalse
addExtensions是否创建Extension-List清单条目booleanfalse
classpathLayoutType在创建的Class-Path中格式化条目时要使用的布局类型(3个值simple、repository、custom)Stringsimple
classpathMavenRepositoryLayout
classpathPrefixClass-Path前缀String“”
customClasspathLayout
mainClassThe Main-Class manifest entry(主程序入口)String
packageNameThe Main-Class manifest entr
useUniqueVersions

manifest主要关注的属性有:addClasspath、classpathPrefix、mainClass

manifestSection 默认设置即可
ElementDescriptionType
nameThe name of the sectionString
manifestEntriesA list of key/value pairs to add to the manifest(添加到manifest的一组键值对)Map
pom.properties content

The auto created pom.properties file will contain the following content:

version=${project.version}
groupId=${project.groupId}
artifactId=${project.artifactId}

2. maven-assembly-plugin

3. maven-shade-plugin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帅胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值