1_maven與eclispe環境搭建
【1】eclipse 4.3以前的版本需要爲eclipse安裝m2e插件。可以採用link,marketplace或install new software來安裝(參照其他文章)
本文使用的是eclipse Kepler 4.3已經自己集成了maven插件。
集成好後,在eclipse window-Preferences 下面多出了maven選項
【2】需要配置Installations,配置外置的maven,也就是文章1中配置好的maven環境。
使用Add按鈕,添加本地的maven。
2_利用eclipse創建maven項目了。
(1) New --Maven--Maven Project
(2) 設置項目存儲位置
(3)設置創建maven項目的模板
quickstart是創建普通java項目的模板,webapp是創建web項目的模板,在文章2 中有講解。
(4)設置 Maven座標
設置完成即可完成項目的創建。
3_利用eclipse進行項目的構建,測試,運行。
【1】右鍵pom.xml,Run as
【2】也可以自定義運行的命令,點擊2 Maven build..然後輸入自定義命令。
【3】如果是web項目,可以在pom.xml中配置cargo,使其自動部署到tomcat上。
<build>
<finalName>web1</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<home>D:\Tomcat7.0</home>
</container>
<configuration>
<type>existing</type>
<home>D:\Tomcat7.0</home>
</configuration>
</configuration>
<executions>
<execution>
<id>cargo-run</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
以上爲簡單配置,後續會專門講解cargo的配置