共计 9605 个字符,预计需要花费 25 分钟才能阅读完成。
拓展浏览
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 包治理平台 -07-plugins 常见插件介绍
maven 包治理平台 -08-nexus 本人搭建 maven 仓库
Maven Archetype
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] <<< maven-archetype-plugin:2.4:create-from-project (default-cli) < generate-sources @ archetype <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.4:create-from-project (default-cli) @ archetype ---
[INFO] Setting default groupId: com.ryo
[INFO] Setting default artifactId: archetype
[INFO] Setting default version: 1.0.0
[INFO] Setting default package: com.ryo
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building archetype-archetype 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ archetype-archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ archetype-archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-archetype-plugin:2.4:jar (default-jar) @ archetype-archetype ---
[INFO] Building archetype jar: /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/target/archetype-archetype-1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.835 s
[INFO] Finished at: 2016-06-11T21:57:36+08:00
[INFO] Final Memory: 14M/309M
[INFO] ------------------------------------------------------------------------
[INFO] Archetype project created in /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.955 s
[INFO] Finished at: 2016-06-11T21:57:36+08:00
[INFO] Final Memory: 14M/245M
[INFO] ------------------------------------------------------------------------
装置
$ cd target/generated-sources/archetype/
$ mvn install
日志
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building archetype-archetype 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ archetype-archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ archetype-archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-archetype-plugin:2.4:jar (default-jar) @ archetype-archetype ---
[INFO] Building archetype jar: /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/target/archetype-archetype-1.0.0
[INFO]
[INFO] --- maven-archetype-plugin:2.4:integration-test (default-integration-test) @ archetype-archetype ---
[INFO] Processing Archetype IT project: basic
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: archetype-archetype:1.0.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: archetype.it
[INFO] Parameter: artifactId, Value: basic
[INFO] Parameter: version, Value: 0.1-SNAPSHOT
[INFO] Parameter: package, Value: it.pkg
[INFO] Parameter: packageInPathFormat, Value: it/pkg
[INFO] Parameter: version, Value: 0.1-SNAPSHOT
[INFO] Parameter: package, Value: it.pkg
[INFO] Parameter: groupId, Value: archetype.it
[INFO] Parameter: artifactId, Value: basic
[WARNING] Don't override file /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/target/test-classes/projects/basic/project/basic/.idea/copyright/profiles_settings.xml
[INFO] project created from Archetype in dir: /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/target/test-classes/projects/basic/project/basic
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ archetype-archetype ---
[INFO] Installing /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/target/archetype-archetype-1.0.0.jar to /Users/houbinbin/.m2/repository/com/ryo/archetype-archetype/1.0.0/archetype-archetype-1.0.0.jar
[INFO] Installing /Users/houbinbin/IT/code/branches/archetype/target/generated-sources/archetype/pom.xml to /Users/houbinbin/.m2/repository/com/ryo/archetype-archetype/1.0.0/archetype-archetype-1.0.0.pom
[INFO]
[INFO] --- maven-archetype-plugin:2.4:update-local-catalog (default-update-local-catalog) @ archetype-archetype ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.885 s
[INFO] Finished at: 2016-06-11T22:00:07+08:00
[INFO] Final Memory: 15M/309M
[INFO] ------------------------------------------------------------------------
删除不须要的我的项目原型
- maven 本地的我的项目我的项目原型默认寄存在:
~/.m2/repository/archetype-catalog.xml
你能够手动批改此文件
- deploy 公布
pom.xml 文件中指定:
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Releases Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshots Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
执行:
$ 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] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: local -> 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<version>/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
本文由博客一文多发平台 OpenWrite 公布!
正文完