Maven - 实例-3-自动创建Maven目录骨架

Posted Anliven - DevOpsNew

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Maven - 实例-3-自动创建Maven目录骨架相关的知识,希望对你有一定的参考价值。

archetype插件用于创建符合maven规定的目录骨架

方式一:根据提示设置相关参数

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects
$ ll
total 4
drwxr-xr-x 1 guowli 1049089 0 Sep  1 16:50 Test/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 17:14 TestMaven/
drwxr-xr-x 1 guowli 1049089 0 Oct 20 17:28 TestMaven02/

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects
$ mkdir TestMaven03

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects
$ cd TestMaven03

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven03
$ mvn archetype:generate
[INFO] Scanning for projects...
Downloading: http://central.maven.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
......
......
......
Choose archetype:
1: remote -> am.ik.archetype:maven-reactjs-blank-archetype (Blank Project for React.js)
......
......
......
1057: remote -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
......
......
......
1962: remote -> us.fatehi:schemacrawler-archetype-plugin-lint (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1057:
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6: 6
......
......
......
Define value for property ‘groupId‘: anliven.testmaven03
Define value for property ‘artifactId‘: testmaven03
Define value for property ‘version‘ 1.0-SNAPSHOT: : 0.0.1-SNAPSHOT
Define value for property ‘package‘ anliven.testmaven03: : anliven.testmaven03
Confirm properties configuration:
groupId: anliven.testmaven03
artifactId: testmaven03
version: 0.0.1-SNAPSHOT
package: anliven.testmaven03
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: D:\Anliven-Running\Zen\EclipseProjects\TestMaven03
[INFO] Parameter: package, Value: anliven.testmaven03
[INFO] Parameter: groupId, Value: anliven.testmaven03
[INFO] Parameter: artifactId, Value: testmaven03
[INFO] Parameter: packageName, Value: anliven.testmaven03
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: D:\Anliven-Running\Zen\EclipseProjects\TestMaven03\testmaven03
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:25 min
[INFO] Finished at: 2017-10-20T17:56:44+08:00
[INFO] Final Memory: 17M/208M
[INFO] ------------------------------------------------------------------------

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven03
$ ls -l
total 0
drwxr-xr-x 1 guowli 1049089 0 Oct 20 17:56 testmaven03/

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven03
$ ls -l testmaven03/
total 4
-rw-r--r-- 1 guowli 1049089 790 Oct 20 17:56 pom.xml
drwxr-xr-x 1 guowli 1049089   0 Oct 20 17:56 src/

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven03
$ ls -l testmaven03/src/main/java/anliven/testmaven03/App.java
-rw-r--r-- 1 guowli 1049089 195 Oct 20 17:56 testmaven03/src/main/java/anliven/testmaven03/App.java

[email protected] MINGW64 /d/Anliven-Running/Zen/EclipseProjects/TestMaven03
$ ls -l testmaven03/src/test/java/anliven/testmaven03/AppTest.java
-rw-r--r-- 1 guowli 1049089 685 Oct 20 17:56 testmaven03/src/test/java/anliven/testmaven03/AppTest.java

方式二:一次性指定相关参数

$ mvn archetype:generate -DgroupId=anliven.testmaven03 -DartifactId=testmaven03 -Dversion= 0.0.1-SNAPSHOT -Dpackage=anliven.testmaven03
  • -DgroupId=组织名,公司网址的反写+项目名
  • -DartifactId=项目名-模块名
  • -Dversion=版本号
  • -Dpackage=代码所在的包名

以上是关于Maven - 实例-3-自动创建Maven目录骨架的主要内容,如果未能解决你的问题,请参考以下文章

IDEA中maven的目录路径总是自动更改?

maven自动创建项目目录骨架

Mybaits 快速入门代码实例(maven代码版)

maven自动编译脚本

约定的目录结构说明

Jenkins 创建自由风格Maven类型和流水线类型的任务,进行项目拉取编译自动部署