Maven3種打包方式中maven_第1頁
Maven3種打包方式中maven_第2頁
Maven3種打包方式中maven_第3頁
Maven3種打包方式中maven_第4頁
Maven3種打包方式中maven_第5頁
已閱讀5頁,還剩1頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

第Maven3種打包方式中mavenmaven-jar-plugin,默認的打包插件,用來打普通的projectJAR包;

maven-shade-plugin,用來打可執(zhí)行JAR包,也就是所謂的fatJAR包;

maven-assembly-plugin,支持自定義的打包結(jié)構(gòu),也可以定制依賴項等。

我們?nèi)粘J褂玫囊詍aven-assembly-plugin為最多,因為大數(shù)據(jù)項目中往往有很多shell腳本、SQL腳本、.properties及.xml配置項等,采用assembly插件可以讓輸出的結(jié)構(gòu)清晰而標準化。

要使用該插件,就在項目pom文件中加入以下內(nèi)容。

build

plugins

plugin

groupIdorg.apache.maven.plugins/groupId

artifactIdmaven-assembly-plugin/artifactId

version${maven-assembly-plugin.version}version

executions

execution

idmake-assembly/id

!--綁定到package生命周期--

phasepackage/phase

goals

!--只運行一次--

goalsingle/goal

/goals

/execution

/executions

configuration

!--配置描述符文件--

descriptorsrc/main/assembly/assembly.xml/descriptor

!--也可以使用Maven預配置的描述符

descriptorRefs

descriptorRefjar-with-dependencies/descriptorRef

/descriptorRefs--

/configuration

/plugin

/plugins

/build

assembly插件的打包方式是通過descriptor(描述符)來定義的。

Maven預先定義好的描述符有bin,src,project,jar-with-dependencies等。比較常用的是jar-with-dependencies,它是將所有外部依賴JAR都加入生成的JAR包中,比較傻瓜化。

但要真正達到自定義打包的效果,就需要自己寫描述符文件,格式為XML。下面是我們的項目中常用的一種配置。

assembly

idassembly/id

formats

formattar.gz/format

/formats

includeBaseDirectorytrue/includeBaseDirectory

fileSets

fileSet

directorysrc/main/bin/directory

includes

include*.sh/include

/includes

outputDirectorybin/outputDirectory

fileMode0755/fileMode

/fileSet

fileSet

directorysrc/main/conf/directory

outputDirectoryconf/outputDirectory

/fileSet

fileSet

directorysrc/main/sql/directory

includes

include*.sql/include

/includes

outputDirectorysql/outputDirectory

/fileSet

fileSet

directorytarget/classes//directory

includes

include*.properties/include

include*.xml/include

include*.txt/include

/includes

outputDirectoryconf/outputDirectory

/fileSet

/fileSets

files

file

sourcetarget/${project.artifactId}-${project.version}.jar/source

outputDirectory./outputDirectory

/file

/files

dependencySets

dependencySet

unpackfalse/unpack

scoperuntime/scope

outputDirectorylib/outputDirectory

/dependencySet

/dependencySets

/assembly

id與formats

formats是assembly插件支持的打包文件格式,有zip、tar、tar.gz、tar.bz2、jar、war??梢酝瑫r定義多個format。

id則是添加到打包文件名的標識符,用來做后綴。

也就是說,如果按上面的配置,生成的文件就是artifactId{artifactId}-artifactId{version}-assembly.tar.gz。

fileSets/fileSet

用來設(shè)置一組文件在打包時的屬性。

directory:源目錄的路徑。

includes/excludes:設(shè)定包含或排除哪些文件,支持通配符。

fileMode:指定該目錄下的文件屬性,采用Unix八進制描述法,默認值是0644。

outputDirectory:生成目錄的路徑。

files/file

與fileSets大致相同,不過是指定單個文件,并且還可以通過destName屬性來設(shè)置與源文件不同的名稱。

dependencySets/dependencySet

用來設(shè)置工程依賴文件在打包時的屬性。也與fileSets大致相同,不過還有兩個特殊的配置:

unpack:布爾值,false表示將依賴以原來的JAR形式打包,true則表示將依賴解成*.class文件的目錄結(jié)構(gòu)打包。

sco

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論