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實戰》