Maven Eclipse
maven eclipse
eclipse 提供了一個(gè)很好的插件 m2eclipse ,該插件能將 maven 和 eclipse 集成在一起。
在最新的 eclipse 中自帶了 maven,我們打開(kāi),windows->preferences,如果會(huì)出現(xiàn)下面的畫(huà)面:
下面列出 m2eclipse 的一些特點(diǎn):
- 可以在 eclipse 環(huán)境上運(yùn)行 maven 的目標(biāo)文件。
- 可以使用其自帶的控制臺(tái)在 eclipse 中直接查看 maven 命令的輸出。
- 可以在 ide 下更新 maven 的依賴(lài)關(guān)系。
- 可以使用 eclipse 開(kāi)展 maven 項(xiàng)目的構(gòu)建。
- eclipse 基于 maven 的 pom.xml 來(lái)實(shí)現(xiàn)自動(dòng)化管理依賴(lài)關(guān)系。
- 它解決了 maven 與 eclipse 的工作空間之間的依賴(lài),而不需要安裝到本地 maven 的存儲(chǔ)庫(kù)(需要依賴(lài)項(xiàng)目在同一個(gè)工作區(qū))。
- 它可以自動(dòng)地從遠(yuǎn)端的 maven 庫(kù)中下載所需要的依賴(lài)以及源碼。
- 它提供了向?qū)?,為建立?maven 項(xiàng)目,pom.xml 以及在已有的項(xiàng)目上開(kāi)啟 maven 支持。
- 它提供了遠(yuǎn)端的 maven 存儲(chǔ)庫(kù)的依賴(lài)的快速搜索。
在 eclipse 中導(dǎo)入一個(gè) maven 的項(xiàng)目:
- 打開(kāi) eclipse
- 選擇 file > import > option
- 選擇 maven projects 選項(xiàng)。點(diǎn)擊 next 按鈕。
- 選擇項(xiàng)目的路徑,即使用 maven 創(chuàng)建一個(gè)項(xiàng)目時(shí)的存儲(chǔ)路徑。假設(shè)我們創(chuàng)建了一個(gè)項(xiàng)目: consumerbanking. 通過(guò)?maven 構(gòu)建 java 項(xiàng)目?查看如何使用 maven 創(chuàng)建一個(gè)項(xiàng)目。
- 點(diǎn)擊 finish 按鈕。
現(xiàn)在,你可以在 eclipse 中看到 maven 項(xiàng)目。
看一下 consumerbanking 項(xiàng)目的屬性,你可以發(fā)現(xiàn) eclipse 已經(jīng)將 maven 所依賴(lài)的都添加到了它的構(gòu)建路徑里了。
好了,我們來(lái)使用 eclipse 的編譯功能來(lái)構(gòu)建這個(gè) maven 項(xiàng)目。
- 右鍵打開(kāi) consumerbanking 項(xiàng)目的上下文菜單
- 選擇 run 選項(xiàng)
- 然后選擇 maven package 選項(xiàng)
maven 開(kāi)始構(gòu)建項(xiàng)目,你可以在 eclipse 的控制臺(tái)看到輸出日志。
[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] -------------------------------------------------------------------
現(xiàn)在,右鍵點(diǎn)擊 app.java, 選擇 run as 選項(xiàng)。選擇 as java app
你將看到如下結(jié)果:
hello world!
相關(guān)文章
- JDBC 教程
- JDBC 驅(qū)動(dòng)類(lèi)型
- JDBC 連接數(shù)據(jù)庫(kù)范例
- JDBC 連接數(shù)據(jù)庫(kù)步驟
- JDBC Statement, PreparedStatement 和 CallableStatement
- JDBC ResultSet 結(jié)果集
- JDBC Resultset 結(jié)果集范例
- JDBC 事務(wù)保存點(diǎn)范例
- Scala 教程
- Scala 簡(jiǎn)介
- Scala 類(lèi)和對(duì)象
- Scala 文件 I/O
- Spring 教程
- Spring 模塊
- Spring 依賴(lài)注入
- Spring 自動(dòng)裝配
- Spring MVC教程
- Spring MVC表單標(biāo)簽庫(kù)
- Spring security