激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本一区视频在线观看 | 色婷婷久久久亚洲一区二区三区 | 99日韩精品视频 | 国产精品视频2021 | av免费在线观 | 亚洲午夜天堂吃瓜在线 | 久草在线观看福利视频 | 热99在线 | 成人在线观看地址 | 久久亚洲精品久久国产一区二区 | 国产成人77亚洲精品www | 91精品一区二区综合在线 | 久久国产一级 | 欧美18—19sex性护士中国 | 日韩av片在线免费观看 | 13一14毛片免费看 | 久草在线观看福利 | av不卡免费在线 | 亚洲国产精品一 | 一区二区三区日韩视频在线观看 | 国产色视频在线观看免费 | 依人九九宗合九九九 | 午夜色视频在线观看 | 久久久久性视频 | 黑人一区二区三区四区五区 | 一级毛片播放 | 亚洲成人午夜精品 | 国产成人精品免费视频大全最热 | 欧美激情999 | 国产日韩中文字幕 | 欧美成人午夜 | 欧美日韩在线影院 | 日比视频 | 99爱视频| 色婷婷一区二区三区 | 免费观看一区二区三区 | 意大利av在线 | 8x成人在线电影 | 亚洲第一激情 | 午夜精品久久久久久中宇 | 久久99精品久久久久久秒播放器 |