maven archetype

简介: 概括图很形象

概括图很形象,来自https://maven.apache.org/archetype/maven-archetype-plugin/index.html
1.png
1.从工程创建原型
mvn archetype:create-from-project

如果需要参数定制化 
https://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html

2.进入/target/generated-sources/archetype目录

find ./ -name target |xargs rm -rf 删除自动生成的target
    find ./ -name \.\*|grep src|xargs rm -rf 删除.开头的文件
    mvn clean install/deploy

安装archetype到本地仓库
archetype安装的地址是在maven安装目录下面的conf/settings.xml文件中指定的(字节)。

默认会在 ~/.m2 目录下面生成一个archetype-catalog.xml文件(和默认的settings.xml在同一个目录

3.Eclipse创建maven项目过程中,选择的“Default Local”指向的地址就是 ~/.m2,
所以文件archetype-catalog.xml会被eclipse自动读取,使用eclipse创建maven项目的时候可以在”Default Local”一项中找到刚才自定义archetype名字。

当eclipse的maven设置中,User Settings选择的settings.xml指向的本地仓库地址和maven安装目录下的那个settings.xml中指向路径一样的时候,eclipse才能读取得到刚才安装的自定义的archetype的源文件,这样eclipse才能复制源文件并创建项目。

4.卸载安装的archetype,将~/.m2目录下面的archetype-catalog.xml文件中对应的字节段删掉,并且把本地仓库中相应groupId和artifactId下面的文件删掉

5.安装到本地仓库中的archetype只可以被自己使用,如果想要共享,那么必须deploy到内部maven仓库中

6.如果想要生成项目,列出所有的archetype, mvn archetype:generate ;只列出本地archetype,mvn archetype:generate -DarchetypeCatalog=local,
筛选archetype,后面必须加“:”,可以只显示某个groupId下面的archetype

mvn archetype:generate -Dfilter=com.glowd.arch:

7.如果使用的是maven-archetype-plugin 2.4,可以直接在命令行生成archetype工程,不需要进入交互模式,但是最新版的maven已经不支持了,基于安全考虑

mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeCatalog=http://nexus.glowd.com:1998/nexus/content/repositories/releases/com/glowd/sample/sample-archetype/0.0.1/sample-archetype-0.0.1.pom

8.mvn archetype:crawl

扫描整个~/.m2/repository/,将扫描到的所有的archetype进行排序更新,在我们执行mvn archetype:generate -DarchetypeCatalog=local时能够看到所有整理过后的扫描项,
扫描的内容在~/.m2/repository/archetype-catalog.xml中

9.Testing

The user can provide archetype test projects by placing them in src/it/projects folder of their project. Upon creating archetype from the existing project all the test projects will be executed to verify the archetype created by this project is good. Read more about testing maven archetype.
具体参考https://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html

10.Configuration
The create-from-project goal enable the user to provide some sensible configuration using the system properties or a property file.
The system properties permits the user to define the groupId, artifactId, version of the created archetype. They also permits to override the resolved package and to create a partial archetype.
When used, the property file takes precedence over the system properties. It is also the only way to define additional properties in the archetype.

具体参考https://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html

10.Post-generation script
If the user wants to customize the generated project even further, a groovy script named archetype-post-generate.groovy can be added in src/main/resources/META-INF/. This script will end up in the generated archetype’s META-INF folder and will be executed upon creating a project from this archetype. This groovy script has access to the ArchetypeGenerationRequest object, as well as all the System.getProperties() and all the archetype generation properties the user has specified.

相关文章
|
5月前
|
Dubbo Java 应用服务中间件
微服务框架(十)Maven Archetype制作Dubbo项目原型
  此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。   本文为Maven Archetype的制作及使用,使用archetype插件制作Dubbo项目原型
|
12月前
|
Java 数据库连接 Maven
IDEA下Maven骨架(archetype)搭建
通过Maven生成骨架(通用项目目录结构)流程记录
942 1
|
Java Maven Android开发
Eclipse使用Maven创建Web时错误:Could not resolve archetype
转载自:http://blog.csdn.net/afgasdg/article/details/12757433
302 0
Eclipse使用Maven创建Web时错误:Could not resolve archetype
|
前端开发 Java 数据库连接
【小白写工程】关于Maven的Archetype
【小白写工程】关于Maven的Archetype
116 0
|
开发框架 前端开发 Java
JAVA-带您弄清创建Maven项目-Archetype里那些看完茫然不解的骨架
JAVA-带您弄清创建Maven项目-Archetype里那些看完茫然不解的骨架
143 0
|
XML Java Apache
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart
150 0
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart
|
Java 中间件 测试技术
Maven Archetype 多 Module 自定义代码脚手架
大部分公司都会有一个通用的模板项目,帮助你快速创建一个项目。通常,这个项目需要集成一些公司内部的中间件、单元测试、标准的代码格式、通用的代码分层等等。
Maven Archetype 多 Module 自定义代码脚手架
|
Java Apache Maven
[Maven] 从mvn archetype:create命令说起
起因 在使用mvn archetype:create -DgroupId=com.test.demo -DartifactId=news-interface -DarchetypeArtifactId=maven-archetype-webapp在控制创建pom项目时,没有创建成功,错误信...
1217 0
|
域名解析 XML 存储
使用 Maven Archetype 创建 Java 项目模板
本文我们将为大家介绍maven的原型及其特性带来的好处,并且演示如何生成一个原型,以及利用原型来创建一个新项目。
1607 0
使用 Maven Archetype 创建 Java 项目模板