<build> <finalName>hhyz-archetype-web</finalName> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-archetype-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </pluginManagement> </build>
第四步: 從A-min項目中建立maven骨架項目git
打開CMD進入命令行,在項目根目錄裏執行: mvn archetype:create-from-project。web
成功執行完以後,在target/generated-sources/ 下有個archetype目錄,這個就是生成的 archetype。能夠看到這個目錄其實就是普通的maven項目,也就是咱們最終的骨架模板項目,咱們稱之爲A-template項目。apache
有幾個目錄、文件須要說明:mybatis
第五步:改造A-templateeclipse
archetype:create-from-project並不是徹底智能,須要本身稍加修改maven
修改packing的值爲jar或者war測試
<requiredProperties> <requiredProperty key="groupId"/> <requiredProperty key="artifactId"/> <requiredProperty key="version"> <defaultValue>1.0.0</defaultValue> </requiredProperty> </requiredProperties>
在fileSets同級下增長requiredProperties標籤。requiredProperties定義模板項目中一些參數值,內置的參數包括:groupId,artifactId,version,package。本身能夠提供這些參數的默認值,也能夠增長本身額外的參數。大部分狀況下,內置的參數足夠用。fileSet標籤有一個filtered=「true」屬性,表示該fileSet可使用參數變量。在文件中引用參數變量的方式${參數名},例如${package}.一般生成A-template項目時,archetype插件會掃描A-min全部的文件,把須要替換爲參數的地方自動替換。畢竟代碼沒有那麼智能,有些地方會有問題。因此,咱們要檢查每一個文件的參數部分是否是咱們預期的。增長參數、刪除參數來達到咱們的要求。 ui
第六步:部署生成的archetype到本地倉庫spa
cd進入generated-sourced/archetype目錄,運行maven命令:mvn clean install,到這裏咱們的模板骨架項目基本完成。插件
3.使用自定義的模板建立項目
方式一:使用命令行