欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

maven 使用assembly 進行打包的方法

 更新時間:2020年09月04日 11:59:30   作者:zhongzunfa  
這篇文章主要介紹了maven 使用assembly 進行打包的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1. pom 中添加assembly 插件

要使用assembly 進項編譯打包, 首先主要在pom 中的build中添加插件信息, 具體如圖下所示:

<build>
  <finalName>${project.artifactId}</finalName>
  <sourceDirectory>src/main/java</sourceDirectory>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <includes>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
      </includes>
    </resource>
    <resource>
      <directory>${profile.dir}</directory>
      <filtering>true</filtering>
    </resource>
  </resources>

  <plugins>
    <!-- compiler插件參數(shù)設置,指定編碼 -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>utf-8</encoding>
      </configuration>
    </plugin>

    <!--  這個插件是關鍵  -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <!--  這個是assembly 所在位置 -->
        <descriptor>src/main/assembly/assembly.xml</descriptor>
      </configuration>
      <executions>
        <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build> 

2. 創(chuàng)建assembly文件夾和assembly.xml文件

創(chuàng)建assembly文件夾和assembly.xml文件, 這個樣子創(chuàng)建主要是規(guī)范。 

在pom 中已經(jīng)介紹assembly.xml 位置。

<!--  這個是assembly 所在位置 -->
<descriptor>src/main/assembly/assembly.xml</descriptor> 

創(chuàng)建assembly.xml 文件后添加如下內(nèi)容:

<assembly>
  <formats>
    <!--支持 zip,tar,tar.gz,tar.bz2,jar,dir,war 等 -->
    <format>tar.gz</format>
    <format>zip</format>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>src/main/resources</directory>
      <outputDirectory>conf</outputDirectory>
      <fileMode>0644</fileMode>
    </fileSet>
    <fileSet>
      <directory>${profile.dir}</directory>
      <outputDirectory>conf</outputDirectory>
      <!-- 表示的是包含下面格式的資源文件 -->
      <includes>
        <include>*.xml</include>
        <include>*.properties</include>
        <include>**/*.xml</include>
        <include>**/*.properties</include>
      </includes>
      <fileMode>0644</fileMode>
    </fileSet>
    <fileSet>
      <directory>src/main/assembly/bin</directory>
      <outputDirectory>bin</outputDirectory>
      <fileMode>0755</fileMode>
    </fileSet>
  </fileSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly> 

fileMode 官方解釋:

Similar to a UNIX permission, sets the file mode of the files included. THIS IS AN OCTAL VALUE. Format: (User)(Group)(Other) where each component is a sum of Read = 4, Write = 2, and Execute = 1. For example, the value 0644 translates to User read-write, Group and Other

上述的三個fileSet 分別是將resource 下的資源打包到config 目錄下, 將assembly下的bin 啟動相關腳本打包到bin 目錄下, 將maven項目依賴的所有jar 包, 打包到lib 中。 

具體結構如下圖所示:

參考地址:
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

zip.xml 文件配置如下

<assembly 
  xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
  <id>release</id> 
  <formats> 
    <format>zip</format> 
  </formats> 
  <fileSets> 
    <fileSet> 
      <directory>${project.basedir}\src\main\config</directory> 
      <!-- 過濾 --> 
      <excludes> 
        <exclude>*.xml</exclude> 
      </excludes> 
      <outputDirectory>\</outputDirectory> 
    </fileSet> 
  </fileSets> 
   
  <dependencySets> 
    <dependencySet> 
      <useProjectArtifact>true</useProjectArtifact> 
      <outputDirectory>lib</outputDirectory><!-- 將scope為runtime的依賴包打包到lib目錄下。 --> 
      <scope>runtime</scope> 
    </dependencySet> 
  </dependencySets> 
</assembly> 

例:

<assembly>
 <id>assembly</id>
 <formats>
 <format>tar.gz</format>
 </formats>
 <includeBaseDirectory>true</includeBaseDirectory>
 <fileSets>
 <fileSet>
  <directory>${project.build.directory}/resources</directory>
  <outputDirectory>resources</outputDirectory>
  <fileMode>0755</fileMode>
 </fileSet>
 <fileSet>
  <directory>${project.build.directory}/config</directory>
  <outputDirectory>config</outputDirectory>
  <fileMode>0644</fileMode>
 </fileSet>
 <fileSet>
  <directory>${project.build.directory}/bin</directory>
  <outputDirectory>bin</outputDirectory>
  <fileMode>0755</fileMode>
 </fileSet>
 </fileSets>
 <dependencySets>
 <dependencySet>
  <outputDirectory>lib</outputDirectory>
 </dependencySet>
 </dependencySets>
</assembly>

到此這篇關于maven 使用assembly 進行打包的方法的文章就介紹到這了,更多相關maven assembly打包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • rabbitmq結合spring實現(xiàn)消息隊列優(yōu)先級的方法

    rabbitmq結合spring實現(xiàn)消息隊列優(yōu)先級的方法

    本篇文章主要介紹了rabbitmq結合spring實現(xiàn)消息隊列優(yōu)先級的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • 關于easyExcel中讀取Excel表頭的實例說明

    關于easyExcel中讀取Excel表頭的實例說明

    EasyExcel是阿里巴巴開源的一個excel處理框架,以使用簡單、節(jié)省內(nèi)存著稱,下面這篇文章主要給大家介紹了關于easyExcel中讀取Excel表頭的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • Spring計時器stopwatch使用詳解

    Spring計時器stopwatch使用詳解

    這篇文章主要介紹了Spring計時器stopwatch使用詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Java中空指針異常的幾種解決方案

    Java中空指針異常的幾種解決方案

    這篇文章主要介紹了Java中空指針異常的幾種解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 詳細解讀java同步之synchronized解析

    詳細解讀java同步之synchronized解析

    synchronized關鍵字是Java里面最基本的同步手段,下面我們來一起學習一下
    2019-05-05
  • SpringMVC與前端交互案例教程

    SpringMVC與前端交互案例教程

    本篇文章主要介紹了SpringMVC前端和后端數(shù)據(jù)交互總結,具有一定的參考價值,感興趣的小伙伴們可以參考一下。希望能給你帶來幫助
    2021-07-07
  • Arrays.sort如何實現(xiàn)降序排序

    Arrays.sort如何實現(xiàn)降序排序

    這篇文章主要介紹了Arrays.sort如何實現(xiàn)降序排序問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Springboot shiro認證授權實現(xiàn)原理及實例

    Springboot shiro認證授權實現(xiàn)原理及實例

    這篇文章主要介紹了Springboot shiro認證授權實現(xiàn)原理及實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06
  • 關于線程池異步線程中再次獲取線程池資源的問題

    關于線程池異步線程中再次獲取線程池資源的問題

    這篇文章主要介紹了關于線程池異步線程中再次獲取線程池資源的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Java探索之Thread+IO文件的加密解密代碼實例

    Java探索之Thread+IO文件的加密解密代碼實例

    這篇文章主要介紹了Java探索之Thread+IO文件的加密解密代碼實例,具有一定參考價值,需要的朋友可以了解下。
    2017-10-10

最新評論