
- Maven 教程
- Maven - 首頁
- Maven - 概述
- Maven - 環境設定
- Maven - POM
- Maven - 構建生命週期
- Maven - 構建配置檔案
- Maven - 倉庫
- Maven - 外掛
- Maven - 建立專案
- Maven - 構建和測試專案
- Maven - 外部依賴
- Maven - 專案文件
- Maven - 專案模板
- Maven - 快照
- Maven - 構建自動化
- Maven - 管理依賴
- Maven - 部署自動化
- Maven - Web 應用程式
- Maven - Eclipse IDE
- Maven - NetBeans
- Maven - IntelliJ IDEA
- Maven 有用資源
- Maven - 常見問題解答
- Maven - 快速指南
- Maven - 有用資源
- Maven - 討論
Maven - Eclipse IDE
Eclipse 提供了一個優秀的外掛 m2eclipse,它可以無縫地將 Maven 和 Eclipse 整合在一起。
m2eclipse 的一些功能如下所示:
您可以從 Eclipse 中執行 Maven 目標。
您可以使用 Eclipse 自帶的控制檯檢視 Maven 命令的輸出。
您可以使用 IDE 更新 Maven 依賴項。
您可以從 Eclipse 內部啟動 Maven 構建。
它根據 Maven 的 pom.xml 為 Eclipse 構建路徑進行依賴項管理。
它從 Eclipse 工作區解析 Maven 依賴項,無需安裝到本地 Maven 儲存庫(需要依賴項專案位於同一工作區)。
它會自動從遠端 Maven 儲存庫下載所需的依賴項和原始碼。
它提供嚮導來建立新的 Maven 專案、pom.xml 以及為現有專案啟用 Maven 支援。
它提供在遠端 Maven 儲存庫中快速搜尋依賴項的功能。
安裝 m2eclipse 外掛
使用以下連結之一安裝 m2eclipse:
Eclipse | URL |
---|---|
Eclipse 3.5 (Gallileo) | |
Eclipse 3.6 (Helios) |
以下示例將幫助您利用整合 Eclipse 和 Maven 的優勢。
在 Eclipse 中匯入 Maven 專案
開啟 Eclipse。
選擇“檔案 > 匯入 >”選項。
選擇 Maven 專案選項。單擊“下一步”按鈕。

選擇專案位置,使用 Maven 在此處建立了專案。我們在前面的章節中建立了一個 Java 專案 consumer Banking。請參閱“建立 Java 專案”章節,瞭解如何使用 Maven 建立專案。
單擊“完成”按鈕。

現在,您可以在 Eclipse 中看到 Maven 專案。

現在,檢視 consumer Banking 專案屬性。您可以看到 Eclipse 已將 Maven 依賴項新增到 Java 構建路徑。

現在,是時候使用 Eclipse 的 Maven 功能構建此專案了。
- 右鍵單擊 consumerBanking 專案以開啟上下文選單。
- 選擇“以...方式執行”選項。
- 然後選擇 Maven package 選項。
Maven 將開始構建專案。您可以在 Eclipse 控制檯中看到如下輸出:
[INFO] Scanning for projects... [INFO] [INFO] ----------------< com.companyname.bank:consumerBanking >---------------- [INFO] Building consumerBanking 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ consumerBanking --- [INFO] Deleting C:\MVN\consumerBanking\target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ consumerBanking --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ consumerBanking --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] Compiling 1 source file to C:\MVN\consumerBanking\target\classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ consumerBanking --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ consumerBanking --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ consumerBanking --- [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.028 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ consumerBanking --- [INFO] Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.663 s [INFO] Finished at: 2021-12-13T17:34:27+05:30 [INFO] ------------------------------------------------------------------------
現在,右鍵單擊 App.java。選擇“以...方式執行”選項。然後選擇“Java 應用程式”。

您將看到如下結果:
Hello World!