IDEA maven 自定义项目骨架archetype

2020-11-26  本文已影响0人  tree3170

[toc]
[menu]
在创建maven项目的时候,每次都要选择骨架,要重复很多操作,导入jar等,能不能把这种常用的操作做成一个项目,把这个项目做成maven仓库的jar,在IDEA中添加archetype,形成模板。
[图片上传中...(image.png-5b35fa-1606396994455-0)]

创建maven项目
image image image image

在pom.xml文件中加入

<defaultGoal>compile</defaultGoal>
<pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-archetype-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
    </plugins>
</pluginManagement>

image

在模板里添加一些包,在包中要至少要有一个文件:

image
在IDEA的终端Terminal,

执行命令:mvn archetype:create-from-project

mvn archetype:create-from-project

image

编译成功,模板生成了。会生成一个target目录,子目录generated-sources,子目录archetype。

image

进入到target/generated-sources/archetype目录下:执行 mvn clean install 安装到本仓库

mvn clean install 

image
安装本地maven仓库成功:
image

查看本地仓库是否真的成功:
C:\Users\laihouwen.m2\repository\archetype-catalog.xml

image

已成功:

image
    <archetype>
      <groupId>com.learn.lai</groupId>
      <artifactId>base-maven-archetype</artifactId>
      <version>1.0</version>
      <description>base-maven-archetype</description>
    </archetype>

在IDEA中加入archetype模板

image image

新建一个项目,引用base-maven模板:

image image image image

引入的archetype模板成功:

image

删除自定义的archetype模板

找到本机的UserArchetypes.xml文件,C:\Users\laihouwen.IntelliJIdea2019.2\system\Maven\Indices

image image

删除你想删除的archetype模板:

 <archetype groupId="com.learn.lai" artifactId="base-maven-archetype" version="1.0" />

找到本机的archetype-catalog.xml文件
C:\Users\laihouwen.m2\repository/archetype-catalog.xml ,

image image

删除你想删除的archetype模板:

 <archetype>
      <groupId>com.learn.lai</groupId>
      <artifactId>base-maven-archetype</artifactId>
      <version>1.0</version>
      <description>base-maven-archetype</description>
    </archetype>

重新启动IDEA

image

最后最好可以进本地的maven仓库中,将这个无效的jar代码删除。

image
上一篇下一篇

猜你喜欢

热点阅读