本文简单介绍一下使用自己的脚手架创建工程
第一步 创建脚手架工程
- 创建脚手架工程
fly-bom
- 定义好模板(包、配置等)
第二步 生成脚手架原型
方法一 IDE生成
-
打开idea,进入新建工程页面,左侧选择
maven
,并勾选Create from archetype
,点击添加Add archetype
按钮
-
输入脚手架原型的
GroupId
、ArtifactId
(注意要加archetype
后缀)、Version
-
点击
OK
,原型里面出现了我们的脚手架原型
新建工程,原型选择她即可。
方法二 本地生成
- 首先,移到脚手架工程根目录下,执行
mvn archetype:create-from-project
命令创建原型, 打印如下日志,表示原型创建成功
liushiweideMacBook-Pro:workgit liushiwei$ mvn archetype:create-from-project
...
[INFO] ------------------------------------------------------------------------
[INFO] Archetype project created in /Users/liushiwei/Dev/workgit/spring-boot-archetype/target/generated-sources/archetype
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] fly-bom 1.0-SNAPSHOT ............................... SUCCESS [ 3.235 s]
[INFO] fly-bom-api ........................................ SKIPPED
[INFO] fly-bom-common ..................................... SKIPPED
[INFO] fly-bom-dao ........................................ SKIPPED
[INFO] fly-bom-manager .................................... SKIPPED
[INFO] fly-bom-service .................................... SKIPPED
[INFO] fly-bom-web 1.0-SNAPSHOT ........................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.838 s
[INFO] Finished at: 2019-08-09T13:38:59+08:00
[INFO] ------------------------------------------------------------------------
- 然后,移到生成原型的目录(
/Users/liushiwei/Dev/workgit/fly-bom/target/generated-sources/archetype
),执行mvn install
命令,打印如下日志,表示执行成功
liushiweideMacBook-Pro:workgit liushiwei$ cd /Users/liushiwei/Dev/workgit/fly-bom/target/generated-sources/archetype
liushiweideMacBook-Pro:workgit liushiwei$ mvn install
...
[INFO] --- maven-archetype-plugin:3.1.1:update-local-catalog (default-update-local-catalog) @ fly-bom-archetype ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.833 s
[INFO] Finished at: 2019-08-09T13:39:21+08:00
[INFO] ------------------------------------------------------------------------
- 最后,在新的目录下,使用刚才生成的本地原型创建新工程,执行
mvn archetype:generate -DarchetypeCatalog=local
命令,依次按照提示输入即可
liushiweideMacBook-Pro:workgit liushiwei$ mvn archetype:generate -DarchetypeCatalog=local
...
Choose archetype:
1: local -> com.lushwe:fly-bom-archetype (Spring Boot Starters)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :