Eclipse 提供一种卓越的插件 m2eclipse,该插件使得 Maven 和 Eclipse 能够无缝集成。
下面列出 m2eclipse 的一些特点:
使用以下任意一个链接来安装 m2eclipse:
Eclipse | URL |
---|---|
Eclipse 3.5 (Gallileo) | Installing m2eclipse in Eclipse 3.5 (Gallileo) |
Eclipse 3.6 (Helios) | Installing m2eclipse in Eclipse 3.6 (Helios) |
以下的示例可以帮助你有效地利用集成 Eclipse 和 Maven.
现在,你可以在 Eclipse 中看到 Maven 工程。
看一下 consumerBanking 工程的属性,你可以发现 Eclipse 已经将 Maven 所依赖的都添加到了它的构建路径里了。
好了,我们来使用 Eclipse 的编译功能来构建这个 Maven 工程。
Maven 开始构建工程,你可以在 Eclispe 的控制台看到输出日志。
[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] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory:
C:\MVN\consumerBanking\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar]
[INFO] -------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Jul 12 18:18:24 IST 2012
[INFO] Final Memory: 2M/15M
[INFO] -------------------------------------------------------------------
现在,右键点击 App.java. 选择 Run As 选项。选择 As Java App.
你将看到如下结果:
Hello World!