- Maven 使用原型(archetype)插件创建工程
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype$ mvn archetype:generate -DgroupId=person.dusixing -DartifactId=maven_archetype -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /home/duxing/Desktop/maven/maven_archetype
[INFO] Parameter: package, Value: person.dusixing
[INFO] Parameter: groupId, Value: person.dusixing
[INFO] Parameter: artifactId, Value: maven_archetype
[INFO] Parameter: packageName, Value: person.dusixing
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/duxing/Desktop/maven/maven_archetype/maven_archetype
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.994 s
[INFO] Finished at: 2017-10-01T01:57:40+08:00
[INFO] Final Memory: 17M/244M
[INFO] ------------------------------------------------------------------------
创建好的工程目录树
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype/maven_archetype$ tree -f
.
├── ./pom.xml
├── ./README.md
└── ./src
├── ./src/main
│ └── ./src/main/java
│ └── ./src/main/java/person
│ └── ./src/main/java/person/dusixing
│ ├── ./src/main/java/person/dusixing/App.java
│ └── ./src/main/java/person/dusixing/Util.java
└── ./src/test
└── ./src/test/java
└── ./src/test/java/person
└── ./src/test/java/person/dusixing
└── ./src/test/java/person/dusixing/AppTest.java
9 directories, 5 files
- 构建工程
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype/maven_archetype$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven_archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven_archetype ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven_archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/duxing/Desktop/maven/maven_archetype/maven_archetype/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven_archetype ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/duxing/Desktop/maven/maven_archetype/maven_archetype/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven_archetype ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/duxing/Desktop/maven/maven_archetype/maven_archetype/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven_archetype ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/duxing/Desktop/maven/maven_archetype/maven_archetype/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven_archetype ---
[INFO] Surefire report directory: /home/duxing/Desktop/maven/maven_archetype/maven_archetype/target/surefire-reports
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.pom (1.7 kB at 1.2 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.12.4/surefire-providers-2.12.4.pom (2.3 kB at 4.5 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar (26 kB at 31 kB/s)
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running person.dusixing.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven_archetype ---
[INFO] Building jar: /home/duxing/Desktop/maven/maven_archetype/maven_archetype/target/maven_archetype-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.345 s
[INFO] Finished at: 2017-10-01T02:06:17+08:00
[INFO] Final Memory: 23M/233M
[INFO] ------------------------------------------------------------------------
构建好的工程目录树
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype/maven_archetype$ tree -f
.
├── ./pom.xml
├── ./README.md
├── ./src
│ ├── ./src/main
│ │ └── ./src/main/java
│ │ └── ./src/main/java/person
│ │ └── ./src/main/java/person/dusixing
│ │ ├── ./src/main/java/person/dusixing/App.java
│ │ └── ./src/main/java/person/dusixing/Util.java
│ └── ./src/test
│ └── ./src/test/java
│ └── ./src/test/java/person
│ └── ./src/test/java/person/dusixing
│ └── ./src/test/java/person/dusixing/AppTest.java
└── ./target
├── ./target/classes
│ └── ./target/classes/person
│ └── ./target/classes/person/dusixing
│ ├── ./target/classes/person/dusixing/App.class
│ └── ./target/classes/person/dusixing/Util.class
├── ./target/maven_archetype-1.0-SNAPSHOT.jar
├── ./target/maven-archiver
│ └── ./target/maven-archiver/pom.properties
├── ./target/maven-status
│ └── ./target/maven-status/maven-compiler-plugin
│ ├── ./target/maven-status/maven-compiler-plugin/compile
│ │ └── ./target/maven-status/maven-compiler-plugin/compile/default-compile
│ │ ├── ./target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
│ │ └── ./target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
│ └── ./target/maven-status/maven-compiler-plugin/testCompile
│ └── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile
│ ├── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
│ └── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
├── ./target/surefire-reports
│ ├── ./target/surefire-reports/person.dusixing.AppTest.txt
│ └── ./target/surefire-reports/TEST-person.dusixing.AppTest.xml
└── ./target/test-classes
└── ./target/test-classes/person
└── ./target/test-classes/person/dusixing
└── ./target/test-classes/person/dusixing/AppTest.class
24 directories, 16 files
- 生成工程文档
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype/maven_archetype$ mvn site
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven_archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-site-plugin:3.3:site (default-site) @ maven_archetype ---
[WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.9
[INFO] Relativizing decoration links with respect to project URL: http://maven.apache.org
[INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin.
[INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "Dependency Convergence" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "Dependency Information" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "About" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "Plugins" report --- maven-project-info-reports-plugin:2.9
[INFO] Generating "Summary" report --- maven-project-info-reports-plugin:2.9
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.919 s
[INFO] Finished at: 2017-10-01T02:52:27+08:00
[INFO] Final Memory: 22M/374M
[INFO] ------------------------------------------------------------------------
生成文档后的目录树
duxing@duxing-X550JK:~/Desktop/maven/maven_archetype/maven_archetype$ tree -f
.
├── ./pom.xml
├── ./README.md
├── ./src
│ ├── ./src/main
│ │ └── ./src/main/java
│ │ └── ./src/main/java/person
│ │ └── ./src/main/java/person/dusixing
│ │ ├── ./src/main/java/person/dusixing/App.java
│ │ └── ./src/main/java/person/dusixing/Util.java
│ └── ./src/test
│ └── ./src/test/java
│ └── ./src/test/java/person
│ └── ./src/test/java/person/dusixing
│ └── ./src/test/java/person/dusixing/AppTest.java
└── ./target
├── ./target/classes
│ └── ./target/classes/person
│ └── ./target/classes/person/dusixing
│ ├── ./target/classes/person/dusixing/App.class
│ └── ./target/classes/person/dusixing/Util.class
├── ./target/maven_archetype-1.0-SNAPSHOT.jar
├── ./target/maven-archiver
│ └── ./target/maven-archiver/pom.properties
├── ./target/maven-status
│ └── ./target/maven-status/maven-compiler-plugin
│ ├── ./target/maven-status/maven-compiler-plugin/compile
│ │ └── ./target/maven-status/maven-compiler-plugin/compile/default-compile
│ │ ├── ./target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
│ │ └── ./target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
│ └── ./target/maven-status/maven-compiler-plugin/testCompile
│ └── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile
│ ├── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
│ └── ./target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
├── ./target/site
│ ├── ./target/site/css
│ │ ├── ./target/site/css/maven-base.css
│ │ ├── ./target/site/css/maven-theme.css
│ │ ├── ./target/site/css/print.css
│ │ └── ./target/site/css/site.css
│ ├── ./target/site/dependencies.html
│ ├── ./target/site/dependency-convergence.html
│ ├── ./target/site/dependency-info.html
│ ├── ./target/site/images
│ │ ├── ./target/site/images/close.gif
│ │ ├── ./target/site/images/collapsed.gif
│ │ ├── ./target/site/images/expanded.gif
│ │ ├── ./target/site/images/external.png
│ │ ├── ./target/site/images/icon_error_sml.gif
│ │ ├── ./target/site/images/icon_info_sml.gif
│ │ ├── ./target/site/images/icon_success_sml.gif
│ │ ├── ./target/site/images/icon_warning_sml.gif
│ │ ├── ./target/site/images/logos
│ │ │ ├── ./target/site/images/logos/build-by-maven-black.png
│ │ │ ├── ./target/site/images/logos/build-by-maven-white.png
│ │ │ └── ./target/site/images/logos/maven-feather.png
│ │ └── ./target/site/images/newwindow.png
│ ├── ./target/site/index.html
│ ├── ./target/site/plugin-management.html
│ ├── ./target/site/plugins.html
│ ├── ./target/site/project-info.html
│ └── ./target/site/project-summary.html
├── ./target/surefire-reports
│ ├── ./target/surefire-reports/person.dusixing.AppTest.txt
│ └── ./target/surefire-reports/TEST-person.dusixing.AppTest.xml
└── ./target/test-classes
└── ./target/test-classes/person
└── ./target/test-classes/person/dusixing
└── ./target/test-classes/person/dusixing/AppTest.class
28 directories, 40 files
通过target/site/index.html可以查看生成的文档
- 参考资料
- 极客学院wiki Maven教程 创建工程 http://wiki.jikexueyuan.com/project/maven/creating-project.html
- 极客学院wiki Maven教程 构建 & 测试工程 http://wiki.jikexueyuan.com/project/maven/building-and-test-project.html
- 极客学院wiki Maven教程 工程文档 http://wiki.jikexueyuan.com/project/maven/project-documents.html
网友评论