制作maven archetype方法

一直想生成一个archetype,节省初始化项目时间,时间让各个项目的结构及通用配置尽量保持一致。之前试过手动来做这个archetype,发现非常麻烦,很容易出错,最终生成出来的结果也不好。最近发现mvn的archetype插件提供一种从现有项目生成archetype的功能,于是今天便试了一下,果然好用。下面将具体做法记录如下:

首先进行用来做archetype项目的根目录,执行如下命令:

mvn archetype:create-from-project这样将会生成该项目类似的archetype,具体的archetype在target/generated-sources目录下,注意新生成的archetype将会包含该项目中所有的文档

为避免新生成的冗余项目文件太多,需要将新生成archetype中的冗余文档去除,并对其项目结构做一些整理。
1、修改archetype目录下pom.xml,将archetype的名称修改成你喜欢的
2、可以将以原项目名(如uic)命名的文件夹改成_rootArtifactId_,这样生成项目结构时,这个目录名称就会变成新的项目名称了。

这些都整理好了之后,可以将其发布到nexus仓库供其它同事使用了,发布的方法如下:
1、在archetype目录下的pom.xml中添加maven仓库配置:

<distributionManagement>
<repository>
<id>releases</id>
<url>

http://192.168.10.254:8081/nexus/content/repositories/releases

</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>

http://192.168.10.254:8081/nexus/content/repositories/snapshots

</url>
</snapshotRepository>
</distributionManagement>2、运行下面的命令发布archetype


mvn deploy发布成功之后就可以使用下面的命令创建新的项目了。

mvn archetype:generate -DarchetypeGroupId=com.hqb360 -DarchetypeVersion=1.0
-DarchetypeArtifactId=hqb-archetype

【转载地址】http://www.colorfuldays.org/tag/archetype/

猜你喜欢

转载自hck.iteye.com/blog/1938916
今日推荐