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




在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>

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

在IDEA的终端Terminal,
执行命令:mvn archetype:create-from-project
mvn archetype:create-from-project

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

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

安装本地maven仓库成功:

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

已成功:

<archetype>
<groupId>com.learn.lai</groupId>
<artifactId>base-maven-archetype</artifactId>
<version>1.0</version>
<description>base-maven-archetype</description>
</archetype>
在IDEA中加入archetype模板


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




引入的archetype模板成功:

删除自定义的archetype模板
找到本机的UserArchetypes.xml文件,C:\Users\laihouwen.IntelliJIdea2019.2\system\Maven\Indices


删除你想删除的archetype模板:
<archetype groupId="com.learn.lai" artifactId="base-maven-archetype" version="1.0" />
找到本机的archetype-catalog.xml文件
C:\Users\laihouwen.m2\repository/archetype-catalog.xml ,


删除你想删除的archetype模板:
<archetype>
<groupId>com.learn.lai</groupId>
<artifactId>base-maven-archetype</artifactId>
<version>1.0</version>
<description>base-maven-archetype</description>
</archetype>
重新启动IDEA

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

网友评论