如何使用Maven的archetype快速生成一個新項目


Maven的archetype Plugin可能大家都聽過,但不一定都能很好地用好它。缺省地如果你使用

mvn archetype:generate 

 

會從maven的Repository里查找所有支持的arche types,大概有500~600個。正因為是太多了,所以查找起來很是不方便。

其實平時常用的arche type也就那么幾個。像我會用到的:

1.simple start 

2. web app

3. Groovy basic

 

很自然的就會考慮,是不是能什么簡便的方法只需要從這3個組成的list里選擇就可以了。 答案當然是: Yes

實現步驟如下:(本機的Maven Repository目錄在C:\Users\buha\.m2 )

1. 使用mvn archetype:crawl 命令,它會在 C:\Users\buha\.m2\repository目錄下生成一個archetype-catalog.xml文件

2.將archetype-catalog.xml移到上一層目錄,也就是C:\Users\buha\.m2

3.這時再運行mvn archetype:generate -DarchetypeCatalog=local 就可以達到你想要的目的了。

 

 

是不是很方便啊。

Links:http://maven.40175.n5.nabble.com/archetype-catalog-xml-location-archetype-crawl-versus-archetype-generate-td113741.html 

想得到更全的archtetype-catalog.xml 可以訪問: http://repo1.maven.org/maven2/archetype-catalog.xml

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM