1. 程式人生 > >eclipse通過maven-archetype-plugin外掛建立專案原型

eclipse通過maven-archetype-plugin外掛建立專案原型

週末專案老大說回去研究一下maven-archetype-plugin這個外掛,之前maven用的不太多,這個外掛也沒聽說過,但週末簡單看一下,發現這個外掛真的好強大。這幾天看了好多帖子,也做了好多實驗,自己總結了一些經驗,在這向大家分享一下。本人菜雞一枚,大神們如果有不認同的請及時指出。

        我用的是eclipse4.6.2,首先使用eclipse建立一個maven專案,並把專案的想要搭成的基礎框架全都搭好。接下來就開始執行maven命令,建立archetype原型骨架。

       Step1.開啟eclipse建立專案,並將專案配置為初始化狀態,並將專案的pom.xml檔案的version從SNAPSHOT修改為RELEASE(一定要修改為RELEASE,否則後面會出問題

);


Step2.右鍵專案-->Run as Configuration-->Goals中輸入maven命令:archetype:create-from-project-->Run;


Step3.cmd進入本地資源包 %專案路徑%target/gengerated-source/Archetype目錄;


Step4.cmd執行maven命令:mvn install ,安裝到本地倉庫;


Step5.cmd執行maven命令:mvn deploy ,安裝到遠端倉庫;
ps:target/gengerated-source/Archetype目錄下的pom.xml中必須加入distributionManagement標籤,否則將會deploy失敗,distributionManagement標籤中的資訊要和settings.xml中的server,repository資訊對應,標籤內設定的遠端倉庫型別必須是hosts宿主倉庫,否則會deploy失敗,並return code 400


<distributionManagement>
	<repository>
		<id>releases1</id>
		<name>Releases</name>
		<url>http://maven.******.com/nexus/content/repositories/releases/</url>
	</repository>		
</distributionManagement>




Step5.檢視本地或遠端倉庫根目錄中的archetype-calalog.xml檔案,發現會多出一組archetype標籤,檢視標籤中的資訊是否跟archetype原型專案的資訊是否一致,如果一致則代表生成原型成功;
 
  <archetype>
      <groupId>${groupId}</groupId>
      <artifactId>${artifactId}</artifactId>
      <version>0.0.1-RELEASE</version>
      <description>${description}</description>
   </archetype>




Step6.點選Window-->Preferences-->Maven-->Archetypes-->Add Local Catalog | Add Remote Catalog-->指定本地catalog.xml路或遠端catalog.xml的url-->ok

這6步完成之後,基於maven-archetype-plugin外掛生成的專案Archetype就已經完成了,現在就可以去eclipse新建maven,並在選擇Archetype的時候,選擇自己生成的Archetype,如果成功建立則代表生成成功。

大家如有疑問,敬請留言。