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

Maven Eclipse

O Eclipse oferece um excelente plugin m2eclipse Este plugin pode integrar Maven e Eclipse.

O Maven está integrado no Eclipse mais recente, abrimos, Windows->Preferências, se aparecer a seguinte tela:

A seguir, lista m2Alguns recursos do Eclipse:

  • Os arquivos de objetivo do Maven podem ser executados no ambiente Eclipse.

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

  • You can update Maven's 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 in the local Maven repository (dependencies need 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 to create a new Maven project, pom.xml, and enable 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 creating a project with Maven. Suppose we created a project: consumerBanking. Through Construção de Projeto Java com Maven Check how to use Maven to create a project.

  • Click the Finish button.

Now, you can see the Maven project in Eclipse.

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

Alright, let's use Eclipse's 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 starts building 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] Usando a codificação padrão para copiar recursos filtrados.
[INFO] [compiler:compile]
[INFO] Nada para compilar - todas as classes estão atualizadas
[INFO] [resources:testResources]
[INFO] Usando a codificação padrão para copiar recursos filtrados.
[INFO] [compiler:testCompile]
[INFO] Nada para compilar - todas as classes estão atualizadas
[INFO] [surefire:test]
[INFO] Diretório de relatório Surefire: 
C:\MVN\consumerBanking\target\surefire-relatórios
-------------------------------------------------------
 TESTES
-------------------------------------------------------
Executando com.companyname.bank.AppTest
Testes Executados: 1, Falhas: 0, Erros: 0, Ignorados: 0, Tempo decorrido: 0.047 seg
Resultados:
Testes Executados: 1, Falhas: 0, Erros: 0, Ignorados: 0
[INFO] [jar:jar]
[INFO] -------------------------------------------------------------------
[INFO] CONSTRUÇÃO SUCESSO
[INFO] -------------------------------------------------------------------
[INFO] Tempo Total: 1 segundo
[INFO] Finalizado em: Sex Jul 12 18:18:24 IST 2012
[INFO] Memória Final: 2M/15M
[INFO] -------------------------------------------------------------------

Agora, clique com o botão direito do mouse App.java, escolha Executar Como Opções. Escolha Como Java App

Você verá o seguinte resultado:

Olá Mundo!