maven 包管理平台-04-maven archetype 项目原型
2016年8月6日大约 4 分钟
拓展阅读
maven 包管理平台-01-maven 入门介绍 + Maven、Gradle、Ant、Ivy、Bazel 和 SBT 的详细对比表格
maven 包管理平台-02-windows 安装配置 + mac 安装配置
maven 包管理平台-03-maven project maven 项目的创建入门
maven 包管理平台-04-maven archetype 项目原型
maven 包管理平台-05-multi module 多模块
maven 包管理平台-06-常用技巧 实时更新快照/乱码问题/下载很慢/包依赖解决包冲突/如何导入本地 jar
maven 包管理平台-08-nexus 自己搭建 maven 仓库
Maven Archetype
是什么?
简而言之,Archetype 是一个 Maven 项目模板工具包。原型被定义为所有相同类型的其他事物所制作的原始模式或模型。
使用
要基于原型创建新项目,您需要调用 mvn archetype:generate
目标。
如何创建原型?
创建
- 创建
$ mvn archetype:create-from-project
houbinbindeMacBook-Pro:archetype houbinbin$ mvn archetype:create-from-project
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building archetype 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.4:create-from-project (default-cli) > generate-sources @ archetype >>>
[INFO]
[INFO]
releases
Nexus Releases Repository
http://localhost:8081/nexus/content/repositories/releases/
snapshots
Nexus Snapshots Repository
http://localhost:8081/nexus/content/repositories/snapshots/
执行:
$ mvn deploy
使用
$ mkdir /tmp/archetype
$ cd /tmp/archetype
$ mvn archetype:generate -DarchetypeCatalog=local
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] com.ryo:archetype-archetype (archetype-archetype)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Define value for property 'groupId': : com.ryo
Define value for property 'artifactId': : test
Define value for property 'version': 1.0-SNAPSHOT: : 1.0.0
Define value for property 'package': com.ryo: : com.ryo
Confirm properties configuration:
groupId: com.ryo
artifactId: test
version: 1.0.0
package: com.ryo
Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: archetype-archetype:1.0.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.ryo
[INFO] Parameter: artifactId, Value: test
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: package, Value: com.ryo
[INFO] Parameter: packageInPathFormat, Value: com/ryo
[INFO] Parameter: package, Value: com.ryo
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: groupId, Value: com.ryo
[INFO] Parameter: artifactId, Value: test
[WARNING] Don't override file /Users/houbinbin/IT/code/branches/test/test/.idea/copyright/profiles_settings.xml
[INFO] project created from Archetype in dir: /Users/houbinbin/IT/code/branches/test/test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:34 min
[INFO] Finished at: 2016-06-11T22:11:32+08:00
[INFO] Final Memory: 14M/309M
[INFO] ------------------------------------------------------------------------
添加原型

输入您的原型项目的位置,然后您就可以像其他 Maven 原型一样使用它。
移除原型
~/Library/Caches/IntelliJIdea/Maven/Indices/UserArchetypes.xml
打开并编辑此文件,然后重新启动 IntelliJIdea。
生成项目架构
houbinbindeMacBook-Pro:archetype-resources houbinbin$ ls
README.md __rootArtifactId__-dal __rootArtifactId__-surface __rootArtifactId__-util app-demo.iml
__rootArtifactId__-biz __rootArtifactId__-service __rootArtifactId__-test __rootArtifactId__-web pom.xml
houbinbindeMacBook-Pro:archetype-resources houbinbin$ pwd
/Users/houbinbin/IT/code/app-demo/target/generated-sources/archetype/target/classes/archetype-resources
元数据指定 (archetype-metadata.xml
)
houbinbindeMacBook-Pro:maven houbinbin$ ls
archetype-metadata.xml
houbinbindeMacBook-Pro:maven houbinbin$ pwd
/Users/houbinbin/IT/code/app-demo/target/generated-sources/archetype/target/classes/META-INF/maven
示例:
贡献者
binbin.hou