maven+idea构建自己的archetype

前言

1、建立一个模板项目

按照如下目录生成

maven+idea构建自己的archetype_第1张图片

2、根据模板项目生成archetype

进入到项目根目录下

maven+idea构建自己的archetype_第2张图片

在控制台窗口中执行如下命令

mvn archetype:create-from-project 

出现如下提示,表示生成archetype成功

maven+idea构建自己的archetype_第3张图片

这个时候也会在这个目录下多处一个target目录,其中就有archetype的相关信息

maven+idea构建自己的archetype_第4张图片

3、将archetype安装到仓库

这一步我这里只安装到本地,如果安装到自动的私服,需要有相关插件支持,这里不做总结

之后进入到target中的archetype下

cd target/generated-sources/archetype/

执行install命令,安装到本地maven仓库

mvn install

这个会将该archetype的信息加入到本地仓库的archetype-catalog.xml文件中

mvn archetype:crawl

4、idea中加入指定archetype

最好以archetype-catalog.xml文件中的相关信息为准

贴一个生成的archetype-catalog.xml文件,其中的第一个archetype就是我们本地生成的archetype


<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.learngroupId>
      <artifactId>common-learn-archetypeartifactId>
      <version>1.0-SNAPSHOTversion>
      <description>common-learn-archetypedescription>
    archetype>
    <archetype>
      <groupId>org.apache.maven.archetypesgroupId>
      <artifactId>maven-archetype-quickstartartifactId>
      <version>1.0version>
      <description>quickstartdescription>
    archetype>
    <archetype>
      <groupId>org.apache.maven.archetypesgroupId>
      <artifactId>maven-archetype-quickstartartifactId>
      <version>1.4version>
      <description>quickstartdescription>
    archetype>
    <archetype>
      <groupId>org.apache.maven.archetypesgroupId>
      <artifactId>maven-archetype-webappartifactId>
      <version>1.3version>
      <description>webappdescription>
    archetype>
  archetypes>
archetype-catalog>

在idea中输入如下信息即可

maven+idea构建自己的archetype_第5张图片

5、根据自己建立的archetype新建项目

在建立项目的时候,选中指定的archetype即可。

在这里插入图片描述

输入相关项目的groupId和artifcatId之后,建立的项目结构如下所示,与archetype一致。

maven+idea构建自己的archetype_第6张图片

总结

一个maven中archetype简单使用的总结

你可能感兴趣的:(工具,maven)