一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - maven 使用assembly 進行打包的方法

maven 使用assembly 進行打包的方法

2020-09-05 00:09zhongzunfa Java教程

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

1. pom 中添加assembly 插件

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<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插件參數設置,指定編碼 -->
    <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. 創建assembly文件夾和assembly.xml文件

創建assembly文件夾和assembly.xml文件, 這個樣子創建主要是規范。 

在pom 中已經介紹assembly.xml 位置。

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

創建assembly.xml 文件后添加如下內容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<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 中。 

具體結構如下圖所示:

maven 使用assembly 進行打包的方法

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

zip.xml 文件配置如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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>

例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<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打包內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/zhongzunfa/article/details/82465939

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲精品久久7777777 | 香蕉国产人午夜视频在线 | 沟厕okn系列在线播放 | 国产精品久久久久久久人人看 | 午夜影视在线观看 | 国产精品自在线 | 欧美大片一区二区三区 | 天堂俺去俺来也www久久婷婷 | 99精品免费在线 | 72张让男人一看就硬的图片 | 国产好深好硬好爽我还要视频 | 91麻豆国产福利在线观看 | 四虎永久在线精品国产 | 国产一区二区在线观看美女 | 双夫1v2| 4hc44四虎www在线影院男同 | 精品国产乱码久久久久久软件 | 亚洲国产精品日韩高清秒播 | 成人影院免费看 | 天天夜夜草草久久伊人天堂 | 99资源在线观看 | 草莓视频看污 | 亚洲高清国产拍精品影院 | bl文全肉高h湿被灌尿 | 嫩草视频在线观看免费 | 精品久久久久中文字幕日本 | 日韩欧美一区二区三区中文精品 | 暖暖视频免费观看视频中国.韩剧 | 深夜影院a| 91国语精品自产拍在线观看一 | 国产成人精品.一二区 | 色老板在线免费观看 | 欧美丝袜videohd | 午夜十八岁禁 | 久久er国产精品免费观看2 | 色老大在线 | 国产精品欧美亚洲韩国日本99 | chinesespank调教| 毛片在线免费视频 | 四虎e234hcom| 国产成人综合网亚洲欧美在线 |