- Apache Maven:
"Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information." - Ubuntu install:
$ sudo apt-get install maven
- Where is it and version:
$ which mvn /usr/bin/mvn $ mvn -v Apache Maven 3.0.4 Maven home: /usr/share/maven Java version: 1.6.0_31, vendor: Sun Microsystems Inc. Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.2.0-65-generic", arch: "amd64", family: "unix"
- Create first project:
$ mvn \ archetype:generate \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false \ -DgroupId=com.myMaven.app \ -DartifactId=HelloMaven [INFO] Scanning for projects... (Downloading packages...) [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom --- (Downloading packages...) [INFO] Generating project in Batch mode (Downloading packages...) [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.myMaven.app [INFO] Parameter: packageName, Value: com.myMaven.app [INFO] Parameter: package, Value: com.myMaven.app [INFO] Parameter: artifactId, Value: HelloMaven [INFO] Parameter: basedir, Value: /home/linst/ws/study/maven [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/linst/ws/study/maven/HelloMaven [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3:05.835s [INFO] Finished at: Mon Sep 29 11:28:32 CST 2014 [INFO] Final Memory: 9M/239M [INFO] ------------------------------------------------------------------------
- About groupId, artifactId and archetypeArtifactId:
groupId: This element indicates the unique identifier of the organization or group that created the project. artifactId: This element indicates the unique base name of the primary artifact being generated by this project. archetypeArtifactId: The archetype's artifactId.
http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html#archetypeCatalog - The generated tree and files and pom.xml:
. └── HelloMaven ├── pom.xml └── src ├── main │ └── java │ └── com │ └── myMaven │ └── app │ └── App.java └── test └── java └── com └── myMaven └── app └── AppTest.java 12 directories, 3 files
4.0.0 com.myMaven.app HelloMaven jar 1.0-SNAPSHOT HelloMaven http://maven.apache.org junit junit 3.8.1 test - Compile:
$ cd HelloMaven/ $ mvn compile [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building HelloMaven 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ (Downloading packages...) [INFO] [INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ HelloMaven --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/linst/ws/study/maven/HelloMaven/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ HelloMaven --- (Downloading packages...) [INFO] Compiling 1 source file to /home/linst/ws/study/maven/HelloMaven/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 13.615s [INFO] Finished at: Mon Sep 29 15:02:17 CST 2014 [INFO] Final Memory: 8M/239M [INFO] ------------------------------------------------------------------------
. ├── pom.xml ├── src │ ├── main │ │ └── java │ │ └── com │ │ └── myMaven │ │ └── app │ │ └── App.java │ └── test │ └── java │ └── com │ └── myMaven │ └── app │ └── AppTest.java └── target └── classes └── com └── myMaven └── app └── App.class 16 directories, 4 files
- Run:
$ mvn exec:java -Dexec.mainClass=com.myMaven.app.App [INFO] Scanning for projects... (Downloading packages...) [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building HelloMaven 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ HelloMaven --- (Downloading packages...) [WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6. Hello World!@@! [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 50.464s [INFO] Finished at: Mon Sep 29 15:15:47 CST 2014 [INFO] Final Memory: 7M/239M [INFO] ------------------------------------------------------------------------
- References:
http://maven.apache.org/index.html
http://maven.apache.org/guides/getting-started/index.html
http://maven.apache.org/pom.html
http://www.codedata.com.tw/java/understanding-gradle-2-maven/ [Chinese]
http://mkn939.blogspot.tw/2013/03/maven-hellomaven-maven-step-by-step.html [Chinese]
Sunday, September 28, 2014
Apache Maven first project for "archetypeArtifactId=maven-archetype-quickstart"
Labels:
Maven
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment