English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven Eclipse

Eclipse propose une excellente extension m2eclipse , cette extension permet de intégrer Maven et Eclipse.

Maven est intégré dans la dernière version d'Eclipse, nous l'ouvrons, Windows->Préférences, si une fenêtre comme celle-ci apparaît :

Liste des m2Certaines caractéristiques d'Eclipse :

  • Les fichiers cibles de Maven peuvent être exécutés dans l'environnement Eclipse.

  • You can use its built-in console to directly view the output of Maven commands in Eclipse.

  • You can update Maven dependencies under the IDE.

  • You can use Eclipse to build Maven projects.

  • Eclipse implements automated dependency management based on Maven's pom.xml.

  • It resolves the dependencies between Maven and the Eclipse workspace without installing them into the local Maven repository (the dependent project needs to be in the same workspace).

  • It can automatically download the required dependencies and source code from the remote Maven repository.

  • It provides a wizard for creating a new Maven project, pom.xml, and enabling Maven support on existing projects.

  • It provides a quick search for dependencies in the remote Maven repository.

Import a Maven project into Eclipse

  • Open Eclipse

  • Select File > Import > option

  • Select the Maven Projects option. Click the Next button.

  • Select the project path, which is the storage path when a project is created using Maven. Suppose we have created a project: consumerBanking. Through Construction de projet Java avec Maven View how to use Maven to create a project.

  • Click the Finish button.

Now, you can see the Maven project in Eclipse.

Take a look at the properties of the consumerBanking project, you can find that Eclipse has already added all the dependencies of Maven to its build path.

Alright, let's use the Eclipse compilation feature to build this Maven project.

  • Right-click to open the context menu of the consumerBanking project

  • Select the Run option

  • Then select the maven package option

Maven begins to build the project, you can see the output log in the Eclipse console.

[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------
[INFO] Building consumerBanking
[INFO] 
[INFO] Id: com.companyname.bank:consumerBanking:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] -------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Utilisation du codage par défaut pour copier les ressources filtrées.
[INFO] [compiler:compile]
[INFO] Rien à compiler - toutes les classes sont à jour
[INFO] [resources:testResources]
[INFO] Utilisation du codage par défaut pour copier les ressources filtrées.
[INFO] [compiler:testCompile]
[INFO] Rien à compiler - toutes les classes sont à jour
[INFO] [surefire:test]
[INFO] Répertoire de rapport Surefire : 
C:\MVN\consumerBanking\target\surefire-rapports
-------------------------------------------------------
 TÉS TÉS
-------------------------------------------------------
Exécution de com.companyname.bank.AppTest
Tests exécutés : 1, Échecs: 0, Erreurs: 0, Ignorés: 0, Temps écoulé: 0.047 sec
Résultats :
Tests exécutés : 1, Échecs: 0, Erreurs: 0, Ignorés: 0
[INFO] [jar:jar]
[INFO] -------------------------------------------------------------------
[INFO] CONSTRUCTION RÉUSSIE
[INFO] -------------------------------------------------------------------
[INFO] Temps total : 1 second
[INFO] Terminé à : jeu Jul 12 18:18:24 IST 2012
[INFO] Mémoire finale : 2M/15M
[INFO] -------------------------------------------------------------------

Maintenant, cliquez avec le bouton droit App.java, choisissez Exécuter en tant que Options. Choisissez Comme application Java

Vous verrez le résultat suivant :

Bonjour le monde !