Maven定義了不少archetype,能夠用命令mvn archtype:generate 得到列表,而後更具體提示選擇比較適合你的項目骨架。html
可是每一個公司組織都有本身的項目結構習慣,那麼怎麼把已經公司的項目骨架放到公用的地方讓新的項目來套用呢,Maven爲咱們提供了很好的工具。java
Maven Archetypes 的功能如同Velocity模板中替換變量,並根據package名等設置擴展java文件的目錄結構。apache
1、用 mvn archetype:create-from-project 從已有的項目生成Archetype模板到 target/generated-sources/archetype。app
處理過程當中,archetype plugin 要找到package name和變量,將變量轉爲符號,將目錄結構和一些文件作拷貝操做。maven
2、cd target/generated-sources/archetype,而後用mvn install 將Archetype模板安裝到本地maven倉庫裏。ide
三、再你要建立新工程的目錄裏用mvn archetype:generate -DarchetypeCatalog=local命令 ,按照提示輸入項目名,package名等變量,即生成項目工具
不光是apache,還有其餘的公司也提供了maven的archetype項目骨架。很方便。ui
文字太多不形象,畫個圖。spa
附:code
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
Maven provides several Archetype artifacts:
Archetype ArtifactIds | Description |
---|---|
maven-archetype-archetype | An archetype which contains a sample archetype. |
maven-archetype-j2ee-simple | An archetype which contains a simplifed sample J2EE application. |
maven-archetype-mojo | An archetype which contains a sample a sample Maven plugin. |
maven-archetype-plugin | An archetype which contains a sample Maven plugin. |
maven-archetype-plugin-site | An archetype which contains a sample Maven plugin site. |
maven-archetype-portlet | An archetype which contains a sample JSR-268 Portlet. |
maven-archetype-quickstart | An archetype which contains a sample Maven project. |
maven-archetype-simple | An archetype which contains a simple Maven project. |
maven-archetype-site | An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site. |
maven-archetype-site-simple | An archetype which contains a sample Maven site. |
用法:
mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id] -DarchetypeArtifactId=maven-archetype-j2ee-simple