自定义Maven模板(Archetype)

2018-12-27  本文已影响0人  vczyh

常用的Archetype

编写Archetype

自定义archetype关键目录

一个简单的Archetype

[图片上传失败...(image-c556f9-1545899546093)]

完善Archetype

生成本地仓库的Archetype Catalog

mvn archetype:crawl

会扫描本地仓库,并且在${user}/.m2/repository生成archetype-catalog.xml,包含了遍历到的本地archetype,其中包含刚刚自定义的

<?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>com.vczyh.archetypes</groupId>
      <artifactId>archetype-test</artifactId>
      <version>1.0-SHAPSHOT</version>
      <description>test</description>
    </archetype>
    <archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-quickstart</artifactId>
      <version>1.3</version>
      <description>quickstart</description>
    </archetype>
    <archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-quickstart</artifactId>
      <version>1.4</version>
      <description>quickstart</description>
    </archetype>
    <archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-webapp</artifactId>
      <version>1.4</version>
      <description>webapp</description>
    </archetype>
  </archetypes>
</archetype-catalog>

添加到Catalog的方便之处在于不用每次使用archetype时写一长串命令

mvn archetype:generate 

[图片上传失败...(image-92b24e-1545899546093)]

选择archetype的编号,比如这里的11即可

Idea使用Archetype

[图片上传失败...(image-32ce0d-1545899546093)]

添加完成后使用

[图片上传失败...(image-827d7e-1545899546093)]

如果需要额外的参数,需要在这里添加,比如示例中的port,否则创建失败

示例代码

上一篇 下一篇

猜你喜欢

热点阅读