maven-assembly-plugin


订阅专栏
一、maven打包工具
使用maven对项目进行打包,可用以下三种plugin

maveb-jar-plugin : maven默认打包插件,用来创建project jar
maven-shade-plugin : 用来打可执行包(executable jar)
maven-assembly-plugin : 支持定制化打包方式
下面简单介绍以下maven-assembly-plugin

二、使用方法
1、descriptorRefs
官方提供的定制化打包方式,包括bin,jar-with-dependencies,src,project。

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <!-- NOTE: We don't need a groupId specification because the group is
             org.apache.maven.plugins ...which is assumed by default.
         -->
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        [...]
</project>


2、descriptors
指定打包文件src/main/assembly/assembly.xml,在该配置文件内指定打包操作。

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
          </descriptors>
        </configuration>
        [...]
</project>

三、配置文件参数解释说明
1、id
<id>release</id>

id标识符,添加到生成文件名称的后缀符。如果指定id的话,目标文件名则是 a r t i f a c t I d − {artifactId}-artifactId−{id}.tar.gz

2、formats
maven-assembly-plugin 支持的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同时指定多个打包格式

<formats>
    <format>tar.gz</format>
    <format>dir</format>
</formats>

3、fileSets
管理一组文件的存放位置,核心元素如下表所示:

元素    类型    作用
outputDirectory    String    指定文件集合的输出目录,该目录是相对于根目录
includes/include*    List    包含文件
excludes/exclude*    List    排除文件
fileMode    String    指定文件属性,使用八进制表达,分别为(User)(Group)(Other)所属属性,默认为 0644
<fileSets>
    <fileSet>
      <includes>
        <include>bin/**</include>
      </includes>
      <fileMode>0755</fileMode>
    </fileSet>

    <fileSet>
      <includes>
        <include>/conf/**</include>
        <include>logs</include>
      </includes>
    </fileSet>

  </fileSets>

files
可以指定目的文件名到指定目录,其他和 fileSets 相同,核心元素如下表所示。

元素    类型    作用
source    String    源文件,相对路径或绝对路径
outputDirectory    String    输出目录
destName    String    目标文件名
fileMode    String    设置文件 UNIX 属性
<files>
    <file>
      <source>README.txt</source>
      <outputDirectory>/</outputDirectory>
    </file>
  </files>

工程目录结构示例

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pxH3zFn3-1623839921009)(C:\Users\liuzhihao.HOLLYSYS\AppData\Roaming\Typora\typora-user-images\1623836394032.png)]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven-assembly-plugin是一个Maven插件,用于创建可部署的归档文件(assembly)。 在Maven项目中,可以使用maven-assembly-plugin来定义和配置自定义的归档文件。这些归档文件可以是可执行的JAR文件、WAR文件或其他自定义格式的文件。 对于mapper的问题,可能是指在使用maven-assembly-plugin时,如何配置mapper。在maven-assembly-plugin中,mapper是用来指定如何映射项目中的文件到归档文件中的位置。 你可以使用以下示例配置来定义mapper: ```xml <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> </plugin> ``` 然后,在`src/main/assembly`目录下创建一个`assembly.xml`文件,定义你的mapper配置。下面是一个简单的示例: ```xml <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>my-assembly</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <directory>${project.build.outputDirectory}</directory> <outputDirectory>/</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </assembly> ``` 在这个示例中,我们定义了一个名为`my-assembly`的归档文件,并将其格式设置为ZIP。然后,我们使用`fileSet`元素指定要包含在归档文件中的文件集。在这个例子中,我们将`${project.build.outputDirectory}`目录下的所有JAR文件包含在归档文件中。 这只是一个简单的示例,你可以根据你的需求进行更复杂的配置。希望这个回答对你有帮助!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值