首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

施用maven3 创建自定义的archetype(项目模板)

2013-03-01 
使用maven3 创建自定义的archetype(项目模板)1、首先使用eclipse创建一个新的maven project,然后把配置好的

使用maven3 创建自定义的archetype(项目模板)

1、首先使用eclipse创建一个新的maven project,然后把配置好的一些公用的东西放到相应的目录下面
? ? 比如说会将一些常用的java代码存放到src/main/java目录下面;
? ? 会将一些通用的配置文件放到src/main/resources目录下面;

? ? 如果是javeEE工程,还会有一些jsp等等的文件存放到src/main/webapp目录下面

?

2、然后在maven project的pom.xml文件中添加插件
? ? ================================================
? ? <plugins>
? ?? ???<plugin>
? ?? ?? ?? ?<groupId>org.apache.maven.plugins</groupId>
? ?? ?? ?? ?<artifactId>maven-archetype-plugin</artifactId>
? ?? ?? ?? ?<version>2.2</version>
? ?? ???</plugin>
? ? </plugins>
? ? ================================================


3、运行maven命令:
? ??mvn archetype:create-from-project(eclipse:Run As-> Mavne Build...->archetype:create-from-project?
? ? 然后会在target目录下面生成generated-sources目录,这个就是生成的 archetype?

4、部署到本地,进入generated-sourced/archetype目录,运行maven命令:
? ??mvn install(eclipse:Run As-> Mavne Install??
? ? 这样就把自定义的archetype安装到本地仓库了。

5、部署到maven服务器,修改generated-sourced/archetype目录下pom.xml,加入如下内容:
? ?? ? <distributionManagement>
? ? ? ? ? ? ? ? <repository>
? ? ? ? ? ? ? ? ? ? ? ? <id>nexus</id>
? ? ? ? ? ? ? ? ? ? ? ? <name>nexus Releases</name>
? ? ? ? ? ? ? ? ? ? ? ? <url>http://...</url>
? ? ? ? ? ? ? ? </repository>
? ? ? ? ? ? ? ? <snapshotRepository>
? ? ? ? ? ? ? ? ? ? ? ? <id>nexus</id>
? ? ? ? ? ? ? ? ? ? ? ? <name>nexus Snapshots</name>
? ? ? ? ? ? ? ? ? ? ? ? <url>http://...</url>
? ? ? ? ? ? ? ? </snapshotRepository>
? ? ? ? </distributionManagement>
? ? 运行maven命令:
? ??mvn deploy(eclipse:Run As-> Mavne Deploy??
? ? 这样就把自定义的archetype安装到maven服务器仓库了。?

1 楼 xtuhcy 昨天   补充一个很重要的东西:

原型部署到nexus后,eclipse如何找到呢?

需要在Maven->Archetype中Add Remoting Catalog

catalog的地址如下:
http://username:password@192.168.0.11:8081/nexus/content/repositories/myapps/archetype-catalog.xml
其中username和password是登录nexus的用户名密码

热点排行