This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docpublic:concepts:java:maven [2014/12/16 16:19] procacci@tem-tsp.eu [ref] |
docpublic:concepts:java:maven [2016/04/26 13:15] (current) procacci@tem-tsp.eu [reprise sous debien generate] |
||
---|---|---|---|
Line 5: | Line 5: | ||
* http:// | * http:// | ||
* http:// | * http:// | ||
+ | * http:// | ||
TP http:// | TP http:// | ||
+ | |||
+ | ==== create ==== | ||
9. Création d'un nouveau projet avec le plug-in archetype | 9. Création d'un nouveau projet avec le plug-in archetype | ||
Line 53: | Line 56: | ||
[INFO] ------------------------------------------------------------------------ | [INFO] ------------------------------------------------------------------------ | ||
</ | </ | ||
+ | |||
+ | ==== reprise sous debian generate ==== | ||
+ | |||
+ | apres execution de ce create sous centos, une reprise de l' | ||
+ | |||
+ | < | ||
+ | $ mvn -e archetype: | ||
+ | + Error stacktraces are turned on. | ||
+ | [INFO] Scanning for projects... | ||
+ | [INFO] Reactor build order: | ||
+ | [INFO] | ||
+ | [INFO] | ||
+ | [INFO] | ||
+ | [INFO] Searching repository for plugin with prefix: ' | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Building Unnamed - com.javaworld.hotels: | ||
+ | [INFO] | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [ERROR] BUILD ERROR | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Failed to configure plugin parameters for: org.apache.maven.plugins: | ||
+ | ... | ||
+ | Cause: Cannot assign configuration entry ' | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Trace | ||
+ | org.apache.maven.lifecycle.LifecycleExecutionException: | ||
+ | </ | ||
+ | |||
+ | solution : faire un generate plutot qu'un create qui est devenu deprecated en maven 3 | ||
+ | |||
+ | http:// | ||
+ | |||
+ | esuite si pb de ce type | ||
+ | |||
+ | < | ||
+ | $ mvn -e archetype: | ||
+ | .... | ||
+ | [ERROR] BUILD FAILURE | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] : org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: | ||
+ | Directory HotelDatabase already exists - please run from a clean directory | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Trace | ||
+ | org.apache.maven.BuildFailureException: | ||
+ | |||
+ | </ | ||
+ | |||
+ | c'est qu'on est pas dans le bon niveau d' | ||
+ | il faut remonter d'un cran | ||
+ | |||
+ | < | ||
+ | $ cd .. | ||
+ | $ ls | ||
+ | application | ||
+ | $ mvn archetype: | ||
+ | [INFO] Scanning for projects... | ||
+ | [INFO] Searching repository for plugin with prefix: ' | ||
+ | ... | ||
+ | [INFO] project created from Old (1.x) Archetype in dir: / | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] BUILD SUCCESSFUL | ||
+ | </ | ||
+ | |||
+ | ==== clean ==== | ||
+ | |||
+ | < | ||
+ | $ mvn clean | ||
+ | [INFO] Scanning for projects... | ||
+ | [INFO] Reactor build order: | ||
+ | [INFO] | ||
+ | [INFO] | ||
+ | [INFO] | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Building Hotel Database tutorial application | ||
+ | [INFO] | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | Downloading: | ||
+ | 3K downloaded | ||
+ | </ | ||
+ | |||
Vous avez maintenant une structure de projet Maven 2 toute neuve. Allez dans le répertoire HotelDatabase pour continuer ce tutoriel. | Vous avez maintenant une structure de projet Maven 2 toute neuve. Allez dans le répertoire HotelDatabase pour continuer ce tutoriel. | ||
Line 64: | Line 148: | ||
</ | </ | ||
+ | recopie des sources | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelDatabase]$ cp / | ||
+ | [disi@cas4 HotelDatabase]$ cp -a / | ||
+ | [disi@cas4 HotelDatabase]$ cp -a / | ||
+ | [disi@cas4 HotelDatabase]$ cp -a / | ||
+ | |||
+ | |||
+ | [disi@cas4 src]$ rm -rf test | ||
+ | [disi@cas4 src]$ cp -a / | ||
+ | [disi@cas4 src]$ ls | ||
+ | main test | ||
+ | [disi@cas4 src]$ ls -l test/ | ||
+ | total 0 | ||
+ | drwxr-xr-x 2 disi disi 32 9 févr. | ||
+ | [disi@cas4 src]$ ls -l test/ | ||
+ | total 4 | ||
+ | -rw-r--r-- 1 disi disi 1605 9 févr. | ||
+ | |||
+ | [disi@cas4 HotelDatabase]$ cp / | ||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | 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: | ||
+ | [WARNING] ' | ||
+ | [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: | ||
+ | [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 / | ||
+ | [INFO] | ||
+ | [INFO] --- maven-compiler-plugin: | ||
+ | [INFO] Nothing to compile - all classes are up to date | ||
+ | [INFO] | ||
+ | [INFO] --- maven-resources-plugin: | ||
+ | [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: | ||
+ | [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! | ||
+ | [INFO] Compiling 1 source file to / | ||
+ | [INFO] | ||
+ | [INFO] --- maven-surefire-plugin: | ||
+ | [INFO] Surefire report directory: / | ||
+ | |||
+ | ------------------------------------------------------- | ||
+ | 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 | ||
+ | ... | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | install | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelDatabase]$ mvn install | ||
+ | [INFO] Scanning for projects... | ||
+ | [WARNING] | ||
+ | [WARNING] Some problems were encountered while building the effective model for com.javaworld.hotels: | ||
+ | [WARNING] ' | ||
+ | [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: | ||
+ | [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 / | ||
+ | [INFO] | ||
+ | [INFO] --- maven-compiler-plugin: | ||
+ | [INFO] Nothing to compile - all classes are up to date | ||
+ | [INFO] | ||
+ | [INFO] --- maven-resources-plugin: | ||
+ | [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: | ||
+ | [INFO] Nothing to compile - all classes are up to date | ||
+ | [INFO] | ||
+ | [INFO] --- maven-surefire-plugin: | ||
+ | [INFO] Surefire report directory: / | ||
+ | |||
+ | ------------------------------------------------------- | ||
+ | T E S T S | ||
+ | ------------------------------------------------------- | ||
+ | Running com.javaworld.hotels.model.HotelModelTest | ||
+ | Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.025 sec | ||
+ | |||
+ | Results : | ||
+ | |||
+ | Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 | ||
+ | |||
+ | [INFO] | ||
+ | [INFO] --- maven-jar-plugin: | ||
+ | [INFO] | ||
+ | [INFO] --- maven-install-plugin: | ||
+ | [INFO] Installing / | ||
+ | [INFO] Installing / | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] BUILD SUCCESS | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Total time: 2.624s | ||
+ | [INFO] Finished at: Sat Dec 20 22:31:05 CET 2014 | ||
+ | [INFO] Final Memory: 7M/16M | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | </ | ||
+ | |||
+ | |||
+ | Creation de la WebApp sous form d'une simple page JSP qui appelra notre class jar ci-dessus | ||
+ | |||
+ | < | ||
+ | [disi@cas4 ~]$ mvn archetype: | ||
+ | [INFO] Scanning for projects... | ||
+ | [INFO] | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Building Maven Stub Project (No POM) 1 | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] | ||
+ | [INFO] --- maven-archetype-plugin: | ||
+ | [WARNING] This goal is deprecated. Please use mvn archetype: | ||
+ | [INFO] Defaulting package to group ID: com.javaworld.hotels | ||
+ | [INFO] ---------------------------------------------------------------------------- | ||
+ | [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp: | ||
+ | [INFO] ---------------------------------------------------------------------------- | ||
+ | [INFO] Parameter: groupId, Value: com.javaworld.hotels | ||
+ | [INFO] Parameter: packageName, | ||
+ | [INFO] Parameter: package, Value: com.javaworld.hotels | ||
+ | [INFO] Parameter: artifactId, Value: HotelWebapp | ||
+ | [INFO] Parameter: basedir, Value: /home/disi | ||
+ | [INFO] Parameter: version, Value: 1.0-SNAPSHOT | ||
+ | [INFO] project created from Old (1.x) Archetype in dir: / | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] BUILD SUCCESS | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Total time: 2.723s | ||
+ | [INFO] Finished at: Sat Dec 20 22:37:44 CET 2014 | ||
+ | [INFO] Final Memory: 9M/21M | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | |||
+ | [disi@cas4 ~]$ cd HotelWebapp/ | ||
+ | [disi@cas4 HotelWebapp]$ | ||
+ | [disi@cas4 HotelWebapp]$ ls | ||
+ | pom.xml | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | recopie du jsp depuis les sources (à la place du default "hello world" ) | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelWebapp]$ cp / | ||
+ | </ | ||
+ | |||
+ | |||
+ | ajout de la dependance dans ce projet WebApp sur le jar de l' | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelWebapp]$ diff -ur pom.xml pom.xml.orig | ||
+ | --- pom.xml 2014-12-20 22: | ||
+ | +++ pom.xml.orig 2014-12-20 22: | ||
+ | @@ -14,11 +14,6 @@ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - < | ||
+ | - </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | install | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelWebapp]$ mvn install | ||
+ | [INFO] Scanning for projects... | ||
+ | [INFO] | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Building HotelWebapp Maven Webapp 1.0-SNAPSHOT | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | Downloading: | ||
+ | Downloaded: http:// | ||
+ | Downloading: | ||
+ | Downloaded: http:// | ||
+ | [INFO] | ||
+ | [INFO] --- maven-resources-plugin: | ||
+ | [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: | ||
+ | [INFO] No sources to compile | ||
+ | [INFO] | ||
+ | [INFO] --- maven-resources-plugin: | ||
+ | [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 / | ||
+ | [INFO] | ||
+ | [INFO] --- maven-compiler-plugin: | ||
+ | [INFO] No sources to compile | ||
+ | [INFO] | ||
+ | [INFO] --- maven-surefire-plugin: | ||
+ | [INFO] No tests to run. | ||
+ | [INFO] Surefire report directory: / | ||
+ | |||
+ | ------------------------------------------------------- | ||
+ | T E S T S | ||
+ | ------------------------------------------------------- | ||
+ | |||
+ | Results : | ||
+ | |||
+ | Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 | ||
+ | |||
+ | [INFO] | ||
+ | [INFO] --- maven-war-plugin: | ||
+ | Downloading: | ||
+ | Downloaded: http:// | ||
+ | ... | ||
+ | Downloaded: http:// | ||
+ | [INFO] Packaging webapp | ||
+ | [INFO] Assembling webapp [HotelWebapp] in [/ | ||
+ | [INFO] Processing war project | ||
+ | [INFO] Copying webapp resources [/ | ||
+ | [INFO] Webapp assembled in [81 msecs] | ||
+ | [INFO] Building war: / | ||
+ | [INFO] WEB-INF/ | ||
+ | [INFO] | ||
+ | [INFO] --- maven-install-plugin: | ||
+ | [INFO] Installing / | ||
+ | [INFO] Installing / | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] BUILD SUCCESS | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | [INFO] Total time: 5.688s | ||
+ | [INFO] Finished at: Sat Dec 20 22:44:02 CET 2014 | ||
+ | [INFO] Final Memory: 8M/20M | ||
+ | [INFO] ------------------------------------------------------------------------ | ||
+ | </ | ||
+ | |||
+ | |||
+ | contenu du war | ||
+ | |||
+ | < | ||
+ | [disi@cas4 HotelWebapp]$ jar tvf ./ | ||
+ | 0 Sat Dec 20 22:44:04 CET 2014 META-INF/ | ||
+ | 123 Sat Dec 20 22:44:02 CET 2014 META-INF/ | ||
+ | 0 Sat Dec 20 22:44:02 CET 2014 WEB-INF/ | ||
+ | 0 Sat Dec 20 22:44:02 CET 2014 WEB-INF/ | ||
+ | 0 Sat Dec 20 22:44:02 CET 2014 WEB-INF/ | ||
+ | 215 Sat Dec 20 22:37:44 CET 2014 WEB-INF/ | ||
+ | 4153 Tue Dec 16 18:04:22 CET 2014 WEB-INF/ | ||
+ | 1571 Sat Dec 20 22:41:22 CET 2014 index.jsp | ||
+ | 0 Sat Dec 20 22:44:04 CET 2014 META-INF/ | ||
+ | 0 Sat Dec 20 22:44:04 CET 2014 META-INF/ | ||
+ | 0 Sat Dec 20 22:44:04 CET 2014 META-INF/ | ||
+ | 892 Sat Dec 20 22:43:54 CET 2014 META-INF/ | ||
+ | 123 Sat Dec 20 22:44:02 CET 2014 META-INF/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | deployement dynamique du war dans tomcat | ||
+ | |||
+ | < | ||
+ | [root@cas4 ~]# ls -l / | ||
+ | total 0 | ||
+ | drwxr-xr-x 5 root tomcat 82 10 déc. 16:25 host-manager | ||
+ | drwxr-xr-x 5 root tomcat 97 10 déc. 16:25 manager | ||
+ | [root@cas4 ~]# cp / | ||
+ | [root@cas4 ~]# ls -l / | ||
+ | total 8 | ||
+ | drwxr-xr-x 5 root | ||
+ | drwxr-xr-x 4 tomcat tomcat | ||
+ | -rw-r--r-- 1 root | ||
+ | drwxr-xr-x 5 root | ||
+ | |||
+ | </ | ||
+ | |||
+ | log tomcat au meme moment | ||
+ | |||
+ | < | ||
+ | [root@cas4 ~]# tail -f / | ||
+ | |||
+ | déc. 20, 2014 11:06:01 PM org.apache.catalina.startup.HostConfig deployWAR | ||
+ | INFOS: Déploiement de l' | ||
+ | |||
+ | </ | ||
+ | |||
+ | http:// | ||
+ | |||
+ | < | ||
+ | Application Tutoriel pour la base de données des hotels | ||
+ | |||
+ | Choisissez une destination | ||
+ | |||
+ | Merci de choisir une ville :  Chercher | ||
+ | Hôtels disponibles à Londres | ||
+ | |||
+ | Nom Adresse Ville Catégorie | ||
+ | Hotel Hilton Trafalgar Square Londres 4 étoiles | ||
+ | Hotel Ibis The City Londres 3 étoiles | ||
+ | </ | ||