在項(xiàng)目中Maven用的一直比較多,以前只知道簡(jiǎn)單的配置一些依賴,所以找了時(shí)間孔浩老師Maven的學(xué)習(xí)視頻學(xué)習(xí)了一下
Maven初步-手動(dòng)建立 Maven 項(xiàng)目
- 1、新建一個(gè)簡(jiǎn)單
Maven項(xiàng)目- 手動(dòng)
Maven項(xiàng)目:按照Maven規(guī)范建立項(xiàng)目路徑和pom.xml
- 手動(dòng)
1、示例
maven-ch01/pom.xml
maven-ch01/src/main/java/......
maven-ch01/src/main/resources/...
maven-ch01/src/test/java/......
maven-ch01/src/test/resources/...
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--modelVersion 這是固定值不用修改 -->
<modelVersion>4.0.0</modelVersion>
<!-- GAV 模塊唯一的坐標(biāo),groupId 一般表示項(xiàng)目 -->
<groupId>org.panpan.hellomaven</groupId>
<!--模塊名稱 -->
<artifactId>maven-ch01</artifactId>
<!-- 版本號(hào) -->
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- 這里放的是依賴的模塊 -->
</dependencies>
</project>
- 2、常用的Maven 命令
mvn compile //編譯
mvn test //測(cè)試
mvn package //打包
mvn install //安裝到本地倉(cāng)庫(kù)
mvn deploy //發(fā)布到倉(cāng)庫(kù)中
- 3、maven 默認(rèn)的中央倉(cāng)庫(kù)的地址
- 在
apache-maven-3.3.9\lib\maven-model-builder-3.3.9.jar\org\apache\maven\model\pom-4.0.0.xml中
- 在
- 4、通過(guò) Maven 自有的固定模式生成 maven 項(xiàng)目
- 由于maven有一些固定的生成模式,所以使用
mvn archetype:generate可以自動(dòng)完成這個(gè)骨架的建立 - 隨后按照命令的指示建立好 maven 項(xiàng)目
- 當(dāng)然我們也可以在命令中就設(shè)定好相關(guān)的參數(shù):
mvn archetype:generate -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version>
- 由于maven有一些固定的生成模式,所以使用
Eclipse 建立 Maven 項(xiàng)目
-
1、在Eclipse中建立 Maven 項(xiàng)目
- 普通的Java項(xiàng)目選擇
maven-archetype-quickstart 1.1 - 輸入相關(guān)的 GAV 就可以快速建立Maven 項(xiàng)目
-
項(xiàng)目 resources 需要自己建立
新建Maven 項(xiàng)目 | center| center
- 普通的Java項(xiàng)目選擇
-
小技巧:
-
Maven骨架快速生成配置- Eclipse 或者 IDEA建立Mavan 項(xiàng)目時(shí),有時(shí)候會(huì)一直處于run狀態(tài),只需要新增一個(gè)配置就可以:
Maven -> Runner -> VM Options : -DarchetypeCatalog=internal
- Eclipse 或者 IDEA建立Mavan 項(xiàng)目時(shí),有時(shí)候會(huì)一直處于run狀態(tài),只需要新增一個(gè)配置就可以:
-
Maven 中的依賴特性
-
1、當(dāng)存在多個(gè)模塊開(kāi)發(fā)時(shí),項(xiàng)目之間就會(huì)存在依賴特性
- 示例:
- 存在三個(gè)模塊: user-core、user-log、user-service
- user-service 依賴于 user-core 和 user-log
- 示例:
-
2、依賴的傳遞性
- 在模塊之間互相依賴之后,可能存在包之間的傳遞性
- 依賴之間的傳遞范圍是基于
<scrop>compile</scrop>,對(duì)于依賴的傳遞而言,主要是針對(duì)compile作用域傳遞,其他的作用域并不會(huì)傳遞
-
3、傳遞的沖突問(wèn)題
- 例1-相同路徑深度:
-
a-->b(1.0V)c-->b(1.1V)d-->a和c,這個(gè)時(shí)候在 d模塊 的pom中,哪一個(gè)依賴先寫就使用先寫依賴的版本。 - 對(duì)于相同路徑深度的模塊中的包依賴,那個(gè)模塊寫在pom依賴前,就依賴哪個(gè)版本
-
- 例2-不同路徑深度依賴
-
a-->b(1.0V)c-->b(1.1V)d-->a和c-->b(1.0V)f-->d和c,如果路徑的長(zhǎng)短不一致就選擇最小路徑f-->b1.1
-
- 精確控制依賴沖突問(wèn)題:如果希望精確的控制依賴包,可以使用依賴的排除功能進(jìn)行控制
- 例1-相同路徑深度:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>user-log</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 排重 user-log 模塊中的 commoms-logging 依賴 -->
<exclusions>
<exclusion>
<groupId>commoms-logging</groupId>
<artifactId>commoms-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Maven 依賴范圍
- 1、
test范圍指的是測(cè)試范圍有效,在編譯和打包時(shí)都不會(huì)使用這個(gè)依賴 - 2、
compile范圍指的是編譯范圍有效,在編譯和打包時(shí)都會(huì)將依賴存儲(chǔ)進(jìn)去 - 3、
provided依賴:在編譯和測(cè)試的過(guò)程有效,最后生成war包時(shí)不會(huì)加入,諸如: servlet-api,因?yàn)閟ervlet-api,tomcat等web服務(wù)器已經(jīng)存在了,如果再打包會(huì)沖突 - 4、
runtime在運(yùn)行的時(shí)候依賴,在編譯的時(shí)候不依賴 - 5、默認(rèn)的依賴范圍是
compile, 也只有compile范圍才能進(jìn)行依賴傳遞
<!-- 測(cè)試范圍的依賴 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- 運(yùn)行的時(shí)候依賴 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>runtime</scope>
</dependency>
Maven的聚合和繼承
- 1、Maven 聚合
- 在maven 模塊中,如果一個(gè)項(xiàng)目每個(gè)模塊都去單獨(dú)的操作這樣會(huì)很不方便,重復(fù)操作太多所以我們可以使用聚合的方法來(lái)進(jìn)行 maven 項(xiàng)目的統(tǒng)一操作
- 在之前三個(gè)模塊的根目錄下新建一個(gè)空白的 maven 項(xiàng)目,主要用于管理這三個(gè)
maven項(xiàng)目,并且pom.xml需要按照下面例子來(lái)建立。
示例: 聚合和繼承的路徑
user-maven/pom.xml
user-maven/user-core
user-maven/user-log
user-maven/user-service
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.panpan.hellomaven</groupId>
<artifactId>user-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 類型為pom 管理 -->
<packaging>pom</packaging>
<!-- module 聚合里面存放是項(xiàng)目模塊的絕對(duì)路徑 -->
<modules>
<module>user-dao</module>
<module>user-log</module>
<module>user-service</module>
</modules>
</project>
- 2、
Maven的繼承- 在 Maven 的每個(gè)模塊項(xiàng)目中,一些包依賴需要重復(fù)的去添加,所以我們可以采用在一個(gè)頂級(jí)的
pom.xml來(lái)統(tǒng)一管理這些模塊和包之間的依賴 - 通常我們會(huì)把 聚合 和 繼承統(tǒng)一在一個(gè)
pom.xml文件中
- 在 Maven 的每個(gè)模塊項(xiàng)目中,一些包依賴需要重復(fù)的去添加,所以我們可以采用在一個(gè)頂級(jí)的
user-maven 中的 pom.xml 配置
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.panpan.hellomaven</groupId>
<artifactId>user-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 類型為pom 管理 -->
<packaging>pom</packaging>
<url>http://maven.apache.org</url>
<!-- module 聚合里面存放是項(xiàng)目模塊的絕對(duì)路徑 -->
<modules>
<module>user-dao</module>
<module>user-log</module>
<module>user-service</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
<lombok.version>1.16.10</lombok.version>
<log4j.version>1.2.17</log4j.version>
<slf4j.version>1.5.2</slf4j.version>
<dbunit.version>2.4.5</dbunit.version>
<mysql.version>5.1.38</mysql.version>
<hibernate.version>4.3.11.Final</hibernate.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>${dbunit.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
在user-dao 中繼承 user-maven 的 pom.xml 文件
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 繼承user-maven 的pomx.ml -->
<parent>
<groupId>org.panpan.hellomaven</groupId>
<artifactId>user-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 繼承的絕對(duì)路徑是pom的文件, 如果是在外層可以不添加這個(gè)配置 -->
<!-- 或默認(rèn)繼承在該模塊的最外層根目錄下 -->
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.panpan.hellomaven</groupId>
<artifactId>user-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>user-dao</name>
<dependencies>
<!-- 對(duì)于繼承過(guò)來(lái)的,可以不用寫上版本號(hào)繼承 user-maven -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
</project>
Nexus repository
nexus 介紹和安裝
- 1、Nexus 介紹
* Nexus 是Maven倉(cāng)庫(kù)管理器,如果你使用Maven,你可以從Maven中央倉(cāng)庫(kù) 下載所需要的構(gòu)件(artifact),但這通常不是一個(gè)好的做法,你應(yīng)該在本地架設(shè)一個(gè)Maven倉(cāng)庫(kù)服務(wù)器,在代理遠(yuǎn)程倉(cāng)庫(kù)的同時(shí)維護(hù)本地倉(cāng)庫(kù),以節(jié)省帶寬和時(shí)間,Nexus就可以滿足這樣的需要。此外,他還提供了強(qiáng)大的倉(cāng)庫(kù)管理功能,構(gòu)件搜索功能,它基于REST,友好的UI是一個(gè)extjs的REST客戶端,它占用較少的內(nèi)存,基于簡(jiǎn)單文件系統(tǒng)而非數(shù)據(jù)庫(kù)。這些優(yōu)點(diǎn)使其日趨成為最流行的Maven倉(cāng)庫(kù)管理器。 - 2、Nexus 安裝
- 你可以從http://nexus.sonatype.org/downloads/ 下載最新版本的Nexus,Nexus提供了兩種安裝方式,一種是內(nèi)嵌Jetty的bundle,只要你有JRE就能直接運(yùn)行。第二種方式是WAR,你只須簡(jiǎn)單的將其發(fā)布到web容器中即可使用。
- Bundle方式安裝
- 解壓nexus-webapp-1.3.0-bundle.zip 至任意目錄,如D:\dev_tools ,然后打開(kāi)CMD,cd至目錄D:\dev_tools\nexus-webapp-1.3.0\bin\jsw\windows-x86-32 ,運(yùn)行Nexus.bat 。你會(huì)看到Nexus的啟動(dòng)日志,當(dāng)你看到“Started SelectChannelConnector@0.0.0.0:8081”之后,說(shuō)明Nexus啟動(dòng)成功了,然后打開(kāi)瀏覽器,訪問(wèn)http://127.0.0.1:8081/nexus
- 要停止Nexus,Ctrl+C即可,此外InstallNexus.bat可以用來(lái)將Nexus安裝成一個(gè)windows服務(wù),其余的腳本則對(duì)應(yīng)了啟動(dòng),停止,暫停,恢復(fù),卸載Nexus服務(wù)。
- WAR方式安裝
- 你需要有一個(gè)能運(yùn)行的web容器,這里以Tomcat為例,加入Tomcat的安裝目錄位于D:\DevInstall\apache-tomcat-7.0.9,首先我們將下載的nexus-webapp-xxx.war 重命名為nexus.war ,然后復(fù)制到D:\DevInstall\apache-tomcat-7.0.9\webapps\nexus.war ,然后啟動(dòng)CMD,cd到D:\DevInstall\apache-tomcat-7.0.9\bin\ 目錄,運(yùn)行startup.bat 。一切OK,現(xiàn)在可以打開(kāi)瀏覽器訪問(wèn)http://127.0.0.1:8080/nexus,你會(huì)得到和上圖一樣的界面。
nexus的配置
- 默認(rèn)情況下,Maven依賴于中央倉(cāng)庫(kù),這是為了能讓Maven開(kāi)箱即用,但僅僅這么做明顯是錯(cuò)誤的,這會(huì)造成大量的時(shí)間及帶寬的浪費(fèi)。既然文章的前面已經(jīng)介紹了如何安裝和配置Nexus,現(xiàn)在我們就要配置Maven來(lái)使用本地的Nexus,以節(jié)省時(shí)間和帶寬資源。
- 我們可以將Repository配置到POM中,但一般來(lái)說(shuō)這不是很好的做法,原因很簡(jiǎn)單,你需要為所有的Maven項(xiàng)目重復(fù)該配置。因此,這里我將Repository的配置放到
settings.xml中:
<profiles>
<profile>
<id>nexusProfile</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Repository</name>
<url>http://127.0.0.1:8080/nexus/content/groups/public/</url>
<!-- 可以下載releases Jar 包 默認(rèn)是true -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 可以下載snapshots Jar包默認(rèn)是false -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 在這激活哪個(gè)profile id,哪個(gè)就生效 -->
<activeProfiles>
<activeProfile>nexusProfile</activeProfile>
</activeProfiles>
- 當(dāng)然,我們還可以配置工廠的鏡像,那設(shè)置工廠的查找范圍。例如只能在本地服務(wù)器的工廠中查詢
<mirrors>
<!-- 工廠的鏡像,只要mirrorOf 中的工廠要訪問(wèn),都會(huì)自動(dòng)來(lái)找鏡像,就不會(huì)再去重要工廠 -->
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<!-- 也可以配置為 * 來(lái)代替-->
<mirrorOf>nexus,central</mirrorOf>
<url>http://192.168.0.221:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
- 在配置了工廠鏡像之后,在之前的
nexusProfile的配置就沒(méi)有必要配置了,但是對(duì)于想要能夠依賴中央工廠中的snapshots版本的鏡像,我們可以采用覆蓋maven中的默認(rèn)配置方式
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<!-- 表示配置中央工廠中的snapshots為true,查找地址為上面配置mirror 鏡像 -->
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
發(fā)布項(xiàng)目到nexus中
- 更常見(jiàn)的用例是:團(tuán)隊(duì)在開(kāi)發(fā)一個(gè)項(xiàng)目的各個(gè)模塊,為了讓自己開(kāi)發(fā)的模塊能夠快速讓其他人使用,你會(huì)想要將snapshot版本的構(gòu)件部署到Maven倉(cāng)庫(kù)中,其他人只需要在POM添加一個(gè)對(duì)于你開(kāi)發(fā)模塊的依賴,就能隨時(shí)拿到最新的snapshot。
- 以下的
pom.xml配置和settings.xml能讓你通過(guò)Maven自動(dòng)化部署構(gòu)件:
<!-- pom.xml -->
<!-- 只要在parent 模塊中配置,后面模塊都繼承就行 -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!-- setting.xml -->
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
生命周期和插件
maven 的三套生命周期
-
1、
clean生命周期-
pre-clean執(zhí)行一些需要在clean之前完成的工作 -
clean移除所有上一次構(gòu)建生成的文件 -
post-clean執(zhí)行一些需要在clean之后立刻完成的工作
-
2、
compile生命周期
validate
generate-sources
process-sources
generate-resources
process-resources 復(fù)制并處理資源文件,至目標(biāo)目錄,準(zhǔn)備打包。
compile 編譯項(xiàng)目的源代碼。 //到這一步完成 compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources 復(fù)制并處理資源文件,至目標(biāo)測(cè)試目錄。
test-compile 編譯測(cè)試源代碼。
process-test-classes
test 使用合適的單元測(cè)試框架運(yùn)行測(cè)試。這些測(cè)試代碼不會(huì)被打包或部署。
prepare-package
package 接受編譯好的代碼,打包成可發(fā)布的格式,如 JAR 。
pre-integration-test
integration-test
post-integration-test
verify
install 將包安裝至本地倉(cāng)庫(kù),以讓其它項(xiàng)目依賴。
deploy 將最終的包復(fù)制到遠(yuǎn)程的倉(cāng)庫(kù),以讓其它開(kāi)發(fā)人員與項(xiàng)目共享。
-
3、
site生命周期-
pre-site執(zhí)行一些需要在生成站點(diǎn)文檔之前完成的工作 -
site生成項(xiàng)目的站點(diǎn)文檔 -
post-site執(zhí)行一些需要在生成站點(diǎn)文檔之后完成的工作,并且為部署做準(zhǔn)備 -
site-deploy將生成的站點(diǎn)文檔部署到特定的服務(wù)器上
-
Maven 插件
Maven 插件介紹
- Maven的核心是它的生命周期,生命周期什么都不做,因此Maven的安裝文件很小。所有的事情都交給了插件來(lái)完成。比如說(shuō),Maven 的default生命周期中定義了一個(gè)compile階段,這個(gè)定義本身什么都不會(huì)做,真正編譯代碼的是Compiler插件,它的groupId是org.apache.maven.plugins,artifactId是maven-compiler-plugin。
- 插件是 maven 的核心,所有執(zhí)行的操作都是基于插件來(lái)完成的
- 為了讓一個(gè)插件中可以實(shí)現(xiàn)眾多的類似功能,maven為插件設(shè)定了目標(biāo),一個(gè)插件中有可能有多個(gè)目標(biāo)
- 其實(shí)生命周期中的重要的每個(gè)階段都是由插件的一個(gè)具體目標(biāo)來(lái)執(zhí)行的
Maven 插件基礎(chǔ)
-
phase: 可以在插件上指定聲明周期的哪一步后面執(zhí)行這個(gè)插件 -
executions-execution: 執(zhí)行什么操作 -
goals-goal: 在綁定phase之后,需要指定插件執(zhí)行的目標(biāo),可以執(zhí)行多個(gè) -
configuration: 配置插件中類的注解參數(shù),這樣可以給插件注明一些參數(shù)的值

Maven Plugin | center
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java_source_version>1.8</java_source_version>
<java_target_version>1.8</java_target_version>
<maven_compiler_plugin_version>3.3</maven_compiler_plugin_version>
<maven_source_plugin_version>2.4</maven_source_plugin_version>
<maven_jar_plugin_version>2.5</maven_jar_plugin_version>
<maven_war_plugin_version>2.5</maven_war_plugin_version>
<maven_deploy_plugin_version>2.8.2</maven_deploy_plugin_version>
<spring.version>4.2.1.RELEASE</spring.version>
</properties>
<build>
<plugins>
......
<!--示例—1: 指定編譯的JDK 版本號(hào) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven_compiler_plugin_version}</version>
<configuration>
<source>${java_source_version}</source>
<target>${java_target_version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!--示例-2:生成的Java源文件的Jar包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven_source_plugin_version}</version>
<executions>
<execution>
<id>attach-sources</id>
<!-- 指定插件的目標(biāo) -->
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
<configuration>
<attach>true</attach>
</configuration>
</plugin>
<!-- 示例-3: 生成Maven War包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven_war_plugin_version}</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<!-- 示例-4: Build a JAR from the current project. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven_jar_plugin_version}</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
</configuration>
</plugin>
......
</plugins>
</build>

