使用Maven Archetype插件构建Maven工程原型模板
创建原型模板
1、在空目录运行archetype:generate上面的命令,待下载完必要的jar包后,首先需要输入内置的原型编号;
1 Choose archetype:
2 1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.)
3 2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)
4 3: internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)
5 4: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An archetype which contains a sample Maven plugin site.
6 This archetype can be layered upon an existing Maven plugin project.)
7 5: internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype which contains a sample JSR-268 Portlet.)
8 6: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
9 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
10 8: internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype which contains a sample Maven site which demonstrates
11 some of the supported document types like APT, XDoc, and FML and demonstrates how
12 to i18n your site. This archetype can be layered upon an existing Maven project.)
13 9: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An archetype which contains a sample Maven site.)
14 10: internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample Maven Webapp project.)
15 Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 7:
2、输入任意编号后,继续下载必要jar包,之后要求分别输入groupId,artifactId,version,package,并确认
1 Define value for property 'groupId': com.aaa
2 Define value for property 'artifactId': bbb
3 Define value for property 'version' 1.0-SNAPSHOT: : 1.0
4 Define value for property 'package' com.aaa: : project
5
6 Y: :
7
8 [INFO] ----------------------------------------------------------------------------
9 [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-archetype:1.0
10 [INFO] ----------------------------------------------------------------------------
11 [INFO] Parameter: basedir, Value: E:\CODE\test
12 [INFO] Parameter: package, Value: project
13 [INFO] Parameter: groupId, Value: com.aaa
14 [INFO] Parameter: artifactId, Value: bbb
15 [INFO] Parameter: packageName, Value: project
16 [INFO] Parameter: version, Value: 1.0
17 [INFO] project created from Old (1.x) Archetype in dir: E:\CODE\test\bbb
18 [INFO] ------------------------------------------------------------------------
19 [INFO] BUILD SUCCESS
20 [INFO] ------------------------------------------------------------------------
21 [INFO] Total time: 11:12 min
22 [INFO] Finished at: 2017-12-02T22:00:49+08:00
23 [INFO] Final Memory: 17M/58M
24 [INFO] ------------------------------------------------------------------------
3、浏览Maven工程
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- aaa
| `-- bbb
| `-- App.java
`-- test
`-- java
`-- com
`-- aaa
`-- bbb
`-- AppTest.java
4、内置原型过多时,可以使用-Dfilter命令过滤
mvn archetype:generate -Dfilter=j2ee
5、在Maven工程的pom.xml目录运行mvn archetype:create-from-project, 将会在target/generated-sources/archetype目录下生成原型工程目录
6、在原型工程pom.xml文件下,执行mvn install来把原型jar包上传到本地仓库
7、这时的原型就可以使用了,在空目录执行mvn archetype:generate -DarchetypeCatalog=local
1 mvn archetype:generate -DarchetypeCatalog=local 2 [INFO] Scanning for projects... 3 [INFO] 4 [INFO] ------------------------------------------------------------------------ 5 [INFO] Building Maven Stub Project (No POM) 1 6 [INFO] ------------------------------------------------------------------------ 7 [INFO] 8 [INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>> 9 [INFO] 10 [INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<< 11 [INFO] 12 [INFO] 13 [INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom --- 14 [INFO] Generating project in Interactive mode 15 [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) 16 Choose archetype: 17 1: local -> com.aaa:bbb-archetype (bbb-archetype) 18 Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
接下来就和第一步一样的流程了。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥