通過
maven-archetype-plugin
插件可以自定義符合我們自己需求的archetype。
Archetype是一個(gè)Maven項(xiàng)目模板工具包。通過Archetype我們可以快速搭建Maven項(xiàng)目。
常見的Archetype:
簡單的maven工程骨架
maven-archetype-quickstart
maven-archetype-simple
簡單的maven web工程骨架
mvn archetype:generate
上面的命令執(zhí)行后會(huì)輸出很多maven官方提供的archetype,我們可以根據(jù)這些archetype來生成項(xiàng)目骨架。
官方提供的archetype不能滿足我們的需求時(shí),我們就需要自定義archetype來方便我們自己使用了。
建好自己想要的目錄,想引用的包。
注意version類型一定是RELEASE版本
然后在創(chuàng)建的maven project的pom.xml文件中添加archetype插件。
<build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-archetype-plugin</artifactId> <version>3.0.0</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </pluginManagement> </build>
1.安裝該archetype項(xiàng)目到你的本地倉庫。
mvn archetype:create-from-project
此時(shí)會(huì)在該項(xiàng)目的target目錄下發(fā)現(xiàn)如下文件:
---target ---generated-sources ---archetype ---our project
進(jìn)入到archetype目錄下,也就是到達(dá)我們項(xiàng)目的根目錄執(zhí)行:
cd target/generated-sources/archetype/
mvn install
[INFO] Installing /home/local/xiao/projects/tmp/project/target/generated-sources/archetype/target/project-1.0-SNAPSHOT.jar to /home/xiao/.m2/repository/com/company/project/1.0-SNAPSHOT/project-1.0-SNAPSHOT.jar [INFO] [archetype:update-local-catalog] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6 seconds [INFO] Finished at: Fri Feb 22 23:23:23 GMT 2016 [INFO] Final Memory: 15M/45M [INFO] ------------------------------------------------------------------------
執(zhí)行crawl命令,生成archetype-catalog.xml:
mvn archetype:crawl
會(huì)發(fā)現(xiàn)在咱們的本地倉庫的根目錄生成archetype-catalog.xml骨架配置文件。
<archetype> <groupId>com.jeiker.archetype-demo</groupId> <artifactId>archetype-demo-archetype</artifactId> <version>1.0.0-RELEASE</version> <description>archetype-demo</description> </archetype>
2.發(fā)布該archetype項(xiàng)目到你的本地私服(nexus)。
mvn deploy
在IDE中配置本地私服(nexus)中archetype的地址。
http://127.0.0.1:8081/nexus/content/groups/public/archetype-catalog.xml
本地
mvn archetype:generate -DarchetypeCatelog=local
遠(yuǎn)程
mvn archetype:generate -DarchetypeCatelog=romote mvn archetype:generate -DarchetypeCatelog=http:localhost:8080/archetype-catalog.xml
創(chuàng)建maven普通項(xiàng)目:
mvn archetype:generate -DgroupId=com.jeiker.xiao -DartifactId=maven-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
創(chuàng)建maven web項(xiàng)目:
mvn archetype:generate -DgroupId=com.jeiker.xiao -DartifactId=maven-demo-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false -DarchetypeCatalog=local
1.幫助命令:
archetype:help
2.爬取一個(gè)maven倉庫,創(chuàng)建目錄文件:
archetype:crawl
3.根據(jù)一個(gè)工程,創(chuàng)建一個(gè)新的archetype:
archetype:create-from-project
4.根據(jù)一個(gè)archetype,創(chuàng)建一個(gè)新的工程:
archetype:generate
5.根據(jù)當(dāng)前的archetype工程,創(chuàng)建一個(gè)jar包:
archetype:jar
6.更新本地的maven目錄:
archetype:update-local-catalog
聯(lián)系客服