maven自定義Archetype

一、建立模板項目

    以下apache

二、模板項目的pom.xml中添加archetype插件

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-archetype-plugin</artifactId>
	<version>3.0.1</version>
</plugin>

三、eclipse創建archetype項目

    若是使用的是eclipse工具,右鍵->Debug As->Maven build,執行mvn archetype:create-from-projecteclipse

四、Archetype安裝到本地倉庫

會生成target\generated-sources\archetype目錄,進入該目錄,執行maven

mvn install

build success,表示Archetype已經安裝到本地倉庫。工具

五、archetype-catalog.xml

    查看Maven安裝目錄下conf文件夾中的settings.xml文件,若是你在此設置了<localRepository>本地倉庫路徑,則Archetype就安裝在這個路徑下。同時在<localRepository>默認路徑:我的文件夾/.m2目錄下會有一個archetype-catalog.xml文件,若是沒有這個文件,就執行 mvn archetype:crawl 命令生成該文件。打開文件,能夠看到Archetype的groupId、artifactId等。ui

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <archetypes>
    <archetype>
      <groupId>test.pro</groupId>
      <artifactId>test.pro-archetype</artifactId>
      <version>1.0.0</version>
      <description>test.pro-archetype</description>
    </archetype>
  </archetypes>
</archetype-catalog>

六、使用自定義的Archetype

    eclipse新建maven project,進入到spa

默認是沒有咱們自定義的Archetype,點擊上面的按鈕插件

添加本地catalogcode

選中生成的archetype-catalog.xml,點擊ok,就能夠獲得xml

七、mvn命令建立項目

mvn archetype:generate

選擇對應的數字,生成本地項目。ip

八、刪除安裝的自定義Archetype

(1)archetype-catalog.xml刪除:打開我的文件夾/.m2目錄下的archetype-catalog.xml文件,將對應的<archetype></archetype>刪除,好比刪除文中剛剛安裝的自定義archetype,那就把第5步中的<archetype></archetype>刪除;

(2)eclipse刪除:如圖

九、修改安裝的自定義Archetype

    某些時候,咱們可能對生成的archetype不太滿意,好比要改動配置文件,雖然也能夠新建項目後直接修改,但這樣每次新建後都要修改,因此就在源項目中先修改了,而後再從新生成一次archetype吧。

(1).執行上面的刪除步驟;

(2).進入項目根目錄,把target\generated-sources\archetype目錄下的文件都刪除掉或者直接把target下的generated-sources文件夾刪掉,而後從新生成Archetype就好了。

相關文章
相關標籤/搜索