This is an old revision of the document!
TP http://dcabasson.developpez.com/articles/java/maven/introduction-maven2/
9. Création d'un nouveau projet avec le plug-in archetype
[disi@cas4 ~]$ mvn archetype:create -DgroupId=com.javaworld.hotels -DartifactId=HotelDatabase -Dpackagename=com.javaworld.hotels [INFO] Scanning for projects... Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom (5 KB at 8.9 KB/sec) ... Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/2.2/maven-archetype-plugin-2.2.jar (86 KB at 843.0 KB/sec) [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-archetype-plugin:2.2:create (default-cli) @ standalone-pom --- Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-catalog/2.2/archetype-catalog-2.2.pom ... Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.jar (5394 KB at 5749.5 KB/sec) [WARNING] This goal is deprecated. Please use mvn archetype:generate instead [INFO] Defaulting package to group ID: com.javaworld.hotels Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/maven-metadata.xml Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/maven-metadata.xml (531 B at 14.8 KB/sec) Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar (7 KB at 137.7 KB/sec) Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom (2 KB at 59.5 KB/sec) [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:RELEASE [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.javaworld.hotels [INFO] Parameter: packageName, Value: com.javaworld.hotels [INFO] Parameter: package, Value: com.javaworld.hotels [INFO] Parameter: artifactId, Value: HotelDatabase [INFO] Parameter: basedir, Value: /home/disi [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/disi/HotelDatabase [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.536s [INFO] Finished at: Tue Dec 16 17:15:08 CET 2014 [INFO] Final Memory: 11M/27M [INFO] ------------------------------------------------------------------------
Vous avez maintenant une structure de projet Maven 2 toute neuve. Allez dans le répertoire HotelDatabase pour continuer ce tutoriel.
[disi@cas4 ~]$ ls HotelDatabase [disi@cas4 ~]$ cd HotelDatabase/ [disi@cas4 HotelDatabase]$ ls pom.xml src
recopie des sources
[disi@cas4 HotelDatabase]$ cp /tmp/application/HotelDatabase/src/main/java/com/javaworld/hotels/model/HotelModel.java src/main/java/com/javaworld/hotels/ [disi@cas4 HotelDatabase]$ cp -a /tmp/application/HotelDatabase/src/main/java/com/javaworld/hotels/businessobjects src/main/java/com/javaworld/hotels/ [disi@cas4 HotelDatabase]$ cp -a /tmp/application/HotelDatabase/src/main/java/com/javaworld/hotels/dao src/main/java/com/javaworld/hotels/ [disi@cas4 HotelDatabase]$ cp -a /tmp/application/HotelDatabase/src/main/java/com/javaworld/hotels/model src/main/java/com/javaworld/hotels/ [disi@cas4 src]$ rm -rf test [disi@cas4 src]$ cp -a /tmp/application/HotelDatabase/src/test . [disi@cas4 src]$ ls main test [disi@cas4 src]$ ls -l test/java/com/javaworld/hotels/ total 0 drwxr-xr-x 2 disi disi 32 9 févr. 2006 model [disi@cas4 src]$ ls -l test/java/com/javaworld/hotels/model/ total 4 -rw-r--r-- 1 disi disi 1605 9 févr. 2006 HotelModelTest.java [disi@cas4 HotelDatabase]$ cp /tmp/application/HotelDatabase/pom.xml .
test unitaires
[disi@cas4 HotelDatabase]$ mvn test [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.javaworld.hotels:HotelDatabase:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 22, column 17 [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. [WARNING] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Hotel Database tutorial application 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ HotelDatabase --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/disi/HotelDatabase/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ HotelDatabase --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ HotelDatabase --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ HotelDatabase --- [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/disi/HotelDatabase/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ HotelDatabase --- [INFO] Surefire report directory: /home/disi/HotelDatabase/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.javaworld.hotels.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec Running com.javaworld.hotels.model.HotelModelTest Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec Results : Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.012s [INFO] Finished at: Tue Dec 16 17:53:55 CET 2014 [INFO] Final Memory: 8M/21M [INFO] ------------------------------------------------------------------------ or [disi@cas4 HotelDatabase]$ mvn test -Dtest=HotelModelTest ... ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.javaworld.hotels.model.HotelModelTest Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.028 sec Results : Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.345s ...