1. 简介
eclipse是一款非常优秀的ide。除了基本的语法标亮,代码补齐,xml编辑等基本功能之外,最新版的eclipse还能很好的支持重构,并且集成了junit,cvs等各种流行工具。可惜eclipse默认没有集成maven的支持。sonatype公司建立了m2eclipse项目,这是一款十分强大的maven插件。
2. m2eclipse安装
启动eclipse之后,在菜单栏中选择help,然后选择install new software,接着就会有一个install对话框。单击work with:字段边上的add按钮,会弹出一个新的add repository对话框。在name字段中输入m2e,在location字段中输入http://m2eclipse.sonatype.org/sites/m2e,然后点击确定按钮。eclipse会下载m2eclipse安装站点上的资源信息。

上图显示了m2eclipse的核心模块maven integration for eclipse(required),选择后单击next按钮,eclipse会自动计算模块间依赖,然后给出一个将被安装的模块列表。
如果一切没有问题,在检查一下eclipse现在是否支持创建maven项目。依次单击菜单栏中的file -> new -> other,在弹出的对话框中,找到maven一项,再将其展开。
如果一切正常,说明m2eclipse已经安装正确了。
注意:
你可能会在使用m2eclipse时遇到类似的错误:
16-1-22 上午11时18分58秒: eclipse is running in a jre, but a jdk is required
some maven plugins may not work when importing projects or updating source folders.
这是因为eclipse默认是运行在jre上的,而m2eclipse的一些功能要求使用jdk。解决方法是配置eclipse安装目录的eclipse.ini文件,添加vm配置指向jdk。
<code>-startup</code>
<code>plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar</code>
<code>--launcher.library</code>
<code>plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502</code>
<code>-showsplash</code>
<code>org.eclipse.platform</code>
<code>--launcher.xxmaxpermsize</code>
<code>256m</code>
<code>-vm</code>
<code>d:\program files (x86)\java\jdk1.7.0_13\bin\javaw.exe</code>
<code>--launcher.defaultaction</code>
<code>openfile</code>
<code>-vmargs</code>
<code>-xms40m</code>
<code>-xmx384m</code>
来源于:《maven实战》