maven-assembly-plugin外掛的使用方法
一. Assembly 是什麼意思?
二. maven-assembly-plugin是什麼?
它是maven中針對打包任務而提供的標準外掛。
三. maven-assembly-plugin外掛的作用?
摘自官網:http://maven.apache.org/plugins/maven-assembly-plugin/
英文原文:The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies,
modules, site documentation, and other files into a single distributable archive.
中文翻譯:Assembly 外掛的主要作用是,允許使用者將專案輸出與它的依賴項、模組、站點文件、和其他檔案一起組裝成一個可分發的歸檔檔案。
(翻譯不一定準確,以英文為準)
四.maven-assembly-plugin外掛在maven專案中如何使用(即使用步驟)?
1. 需要指定一個Assembly描述符檔案。該檔案指定了打包格式,包含的檔案/過濾的檔案等資訊,可以同時指定多個描述符檔案,打包成不同的格式。
2. 在Maven工程的pom.xml檔案裡配置maven-assembly-plugin外掛,引入Assembly描述符檔案。
五. maven專案中Assembly描述符檔案詳解
示例:
<?xml version="1.0" encoding="utf-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <!-- id 識別符號,新增到生成檔名稱的字尾符。如果指定 id 的話(這裡指定的是專案的版本),目標檔案則是 ${artifactId}-${id}.jar。【如terminal-dispatch-5.0.0.0.jar】 --> <id>${project.version}</id> <!-- 指定打包格式。maven-assembly-plugin外掛支援的打包格式有zip、tar、tar.gz (or tgz)、tar.bz2 (or tbz2)、jar、dir、war,可以同時指定多個打包格式 --> <formats> <format>jar</format> </formats> <!-- 指定打的包是否包含打包層目錄(比如finalName是terminal-dispatch,當值為true,所有檔案被放在包內的terminal-dispatch目錄下,否則直接放在包的根目錄下)--> <includeBaseDirectory>true</includeBaseDirectory> <!-- 指定將工程依賴的包打到包裡的指定目錄下 --> <dependencySets> <dependencySet> <useProjectArtifact>true</useProjectArtifact> <!-- 指定打包時是否包含工程自身生成的jar包 --> <outputDirectory>lib</outputDirectory> <!-- 指定將這些依賴包打到包裡lib目錄下 --> <scope>runtime</scope> <!-- 用於管理依賴的部署,runtime表示只在執行時使用 --> </dependencySet> </dependencySets> <!-- 指定要包含的檔案集,可以定義多個fileSet --> <fileSets> <fileSet> <directory>src/main/script/linux/bin</directory> <!-- 指定歸檔檔案(要打的jar包)要包含的目錄(下的檔案及資料夾) --> <outputDirectory>bin</outputDirectory> <!-- 指定要將當前目錄(<directory>標籤中的目錄放在歸檔檔案(要打的jar包)bin目錄下) --> <includes> <include>terminal-dispatch</include> <!-- 精確控制要包含的檔案,<exclude>用於精確控制要排除的檔案 --> <include>server</include> </includes> <fileMode>0755</fileMode> <!-- 設定檔案 UNIX 屬性,是一種讀寫許可權 --> </fileSet> <fileSet> <directory>src/main/resources</directory> <outputDirectory>conf</outputDirectory> <includes> <include>config.properties</include> <include>logback.xml</include> </includes> <fileMode>0644</fileMode> </fileSet> <fileSet> <directory>src/main/script/conf</directory> <outputDirectory>conf</outputDirectory> <includes> <include>wrapper.conf</include> </includes> <fileMode>0644</fileMode> </fileSet> <fileSet> <directory>src/main/script/linux/lib</directory> <outputDirectory>lib</outputDirectory> <includes> <include>libwrapper.so</include> <include>wrapper.jar</include> </includes> <fileMode>0755</fileMode> </fileSet> </fileSets> </assembly>
1. <includeBaseDirectory>true</includeBaseDirectory>標籤作用?
指定打的包是否包含打包層目錄,比如finalName是terminal-dispatch,當值為true,所有檔案被放在包內的terminal-dispatch目錄下,否則直接放在包的根目錄下,
如下圖所示:
2. <fileMode>0755</fileMode>標籤作用?
設定檔案的unix屬性,好像是一種讀寫許可權的設定,linux的內容,我沒有深究,不是特別懂,暫時不多說。
序號 | 取值 | 意義 |
1 | compile | 預設值,適用於所有階段,會隨著專案一起釋出 |
2 | provided | 類似compile,期望JDK、容器或使用者會提供這個依賴。如servlet.jar |
3 | runtime | 只在執行時使用,如JDBC驅動,適用執行和測試階段 |
4 | test | 只在測試時使用,用於編譯和執行測試程式碼。不會隨專案釋出 |
5 | system | 類似provided,需要顯式提供包含依賴的jar,Maven不會在Repository中查詢它 |
六. maven中的pom.xml配置(引入assembly描述符檔案)
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <executions> <execution> <!--執行器 mvn assembly:assembly--> <id>make-zip</id> <!--名字任意 --> <phase>package</phase> <!-- 繫結到package生命週期階段上 --> <goals> <goal>single</goal> <!-- 該打包任務只執行一次 --> </goals> <configuration> <descriptors <descriptor>src/main/script/assembly.xml</descriptor> </descriptors> </configuration>
</execution> </executions> </plugin> <plugins> </build>
相關推薦
maven-assembly-plugin外掛的使用方法
一. Assembly 是什麼意思? 二. maven-assembly-plugin是什麼? 它是maven中針對打包任務而提供的標準外掛。 三. maven-assembly-plugin外掛的作用? 摘自官網:http://maven.apache.org/plugins/maven-ass
使用maven-assembly-plugin外掛打包
在pom.xml中配置 <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI
pom檔案中maven-assembly-plugin外掛學習
一、使用場景 如果專案是微服務架構,可能用到這個外掛的概率比較高,平時普通的專案不需要這樣的實現方式。 如果專案內的一部分通用功能,不需要挨個引用,則需要將通用功能部分達成jar包。 二、Maven-assembly-plugin作用 1、作用:要想將寫的程式
使用maven-assembly-plugin外掛,將maven管理的遠端和本地依賴jar包打入可執行jar包
最近在修改一個小工具,原來的做法是把依賴包都下載到本地目錄,打包時候使用fatjar打包整個專案依賴;現在修改為maven管理依賴包,使用maven-assembly-plugin外掛打包;如果依賴包全部是遠端預設的依賴配置,這樣沒有問題;但裡面有些是自己實現的本地依賴,這個
maven-assembly-plugin外掛打包 jar、tar.gz
使用 maven-assembly-plugin 外掛可以將我們的java application(java應用程式)打成可執行jar,下面簡要介紹一下使用maven-assembly-plugin打包可執行jar和tar.gz。 前面我們已經介紹過maven 多環境打包配
Maven常用外掛介紹:Maven-assembly-plugin外掛
一:外掛的作用 Maven-assembly-plugin外掛作用:要想將寫的程式和它本身所依賴的jar包一起build到一個包裡,是maven中針對打包任務而提供的標準外掛。 其他的功能: 1.
[轉] maven-compiler-plugin 外掛版本資訊錯誤提示的解決方法
使用maven-compiler-plugin 時 POM檔案如下: Xml程式碼 <plugins> <plugin> <artifactId>maven-compiler-plugin<
Maven外掛之maven-assembly-plugin
使用Maven對Web專案進行打包,預設為war包;但有些時候,總是希望打成zip包(亦或其他壓縮包),maven-war-plugin外掛就無能為力了,這時就用到了maven-assembly-plugin外掛了,官方網址: 該外掛能打包成指定格式分發包,更重要的是能夠
maven-compiler-plugin 外掛版本資訊錯誤提示的解決方法
使用maven-compiler-plugin 時,報如下提示,字面意思就是沒有指定版本資訊 [WARNING] [WARNING] Some problems were encountered while building the effective model for
Maven學習總結(27)——Maven自定義打包外掛maven-assembly-plugin詳解
Assembly外掛會生成 “assemblies”, 此特性等同於的Maven 1 distribution plug-in.。該外掛不僅支援建立二進位制歸檔檔案,也支援建立原始碼歸檔檔案。這些as
利用maven-assembly-plugin加載不同環境所需的配置文件
參考 oal 階段 配置 信息 需求 lifecycle ima jar 背景: 如何加載不同環境的配置文件已經成了實在必行的,我們通常利用profile進行,詳情參見我上篇博客 http://www.cnblogs.com/lianshan/p/7347890.htm
使用maven-assembly-plugin打包zipproject
ati XML private odin 能夠 tracking resp clas end 使用Maven對Web項目進行打包。默覺得war包。但有些時候。總是希望打成zip包(亦或其它壓縮包,類似tomcat的那種文件夾結構,直接運行bin/sta
pom文件中maven-assembly-plugin插件學習
instance .com margin inf cto 所在 歸檔 執行 tdi 一、使用場景 如果項目是微服務架構,可能用到這個插件的概率比較高,平時普通的項目不需要這樣的實現方式。 如果項目內的一部分通用功能,不需要挨個引用,則需要將通用功能部分達成jar包。 二
Maven 中maven-assembly-plugin插件的使用筆記 SpringBoot環境
必須 pos div false 項目結構 nts 腳本 posix ons 首先創建一個多模塊的SpringBoot項目 項目結構 父pom的內容如下: <?xml version="1.0" encoding="U
maven-assembly-plugin打包可執行的jar包
main 可執行 assembly ase div streaming jar包 clas lean pom.xml添加 <build> <plugins> <plugin>
maven-assembly-plugin 進行打包
pac sep utf-8 round esc agg 可見 handle imp maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主頁) The Assembly Plugin for Maven is primar
利用maven-resource-plugin外掛進行打包時不同環境下的配置檔案切換
基本概念說明(resources、filter和profile): 1.profiles定義了各個環境的變數id 2.filters中定義了變數配置檔案的地址,其中地址中的環境變數就是上面profile中定義的值 3.resources中是定義哪些目錄下的檔案會被
Maven Assembly Plugin - 如何將Maven工程打成一個可執行jar包
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
spark專案藉助maven-shade-plugin外掛打包依賴
maven配置 maven配置 <profiles> <profile> <id>spark-c
maven-surefire-plugin外掛
轉自:https://sq.163yun.com/blog/article/173632756223238144 maven-surefire-plugin外掛 目前很多專案組的測試程式碼工程都是採用MAVEN+TESTNG的方式構造的。 因此測試程式碼project內的pom.xml就