[Maven] - 安裝與Eclipse搭建

來源:互聯網
上載者:User

標籤:

Maven的具體參考書可以看:《Maven實戰》

下載maven可以到:http://maven.apache.org/

Maven的eclipse基本使用可以在這裡看到:http://www.iteye.com/topic/1123225

 

1、把下載下來的maven的zip檔案隨便解壓到一個地方,比如:f:\tool\apache-maven-3.2.5

 

2、設定環境變數(雷同JAVA_HOME):

新加一個"MAVEN":

把"MAVEN"加到Path中:

 

3、開啟命令列看看maven是否已經正確配置:

能看到上面的資訊說明已經配置正常。

 

4、在命令列中輸入:

mvn help:system

運行結果:

此命令運行完後,將會在windows使用者檔案夾自動產生一個“.m2”的檔案夾,裡頭有一個repository目錄,比如:

C:\Users\xxxxx\.m2

這是本機使用者倉庫,未來使用maven所自動下載的jar包會下載到這。

 

5、Eclipse配置Maven:

點擊eclipse中的window->Perference->Maven->Installations,設定自己下載的Maven。

原eclipse內建的maven可移除,因為大多是版本不一樣,會導致後面有莫名的問題。

 

6、建立Maven的Web項目方法:

6.1)Ctrl + N:

這樣,一個Maven的web項目已經建成。但預設,Project Facet中的Java版本是1.5的,要把它修改為本地的java版本。

6.2)右鍵項目->Properties,把它修改為:

我這裡是使用JBoss,所以要把Dynamic Web Module中的Runtimes設為JBoss:

 

6.2)以Maven的預設契約建立一個src/main/java源檔案夾:

這個檔案夾需要手工建,不能以建立源檔案夾方式來建。(估計是BUG,總會提示已經存在,但事實上又沒有)

6.3)開啟pom.xml檔案,加入依賴(dependency)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>com.my.mavenweb</groupId>  <artifactId>testweb1</artifactId>  <packaging>war</packaging>  <version>0.0.1</version>  <name>testweb1 Maven Webapp</name>  <url>http://maven.apache.org</url>    <properties>      <springframework.version>3.2.0.RELEASE</springframework.version>      <freemarker.version>2.3.20</freemarker.version>      <modelmapper.version>0.7.2</modelmapper.version>  </properties>    <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>3.8.1</version>      <scope>test</scope>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-core</artifactId>        <version>${springframework.version}</version>    </dependency>    <dependency>        <groupId>org.springframework</groupId>        <artifactId>spring-beans</artifactId>        <version>${springframework.version}</version>    </dependency>    <dependency>        <groupId>org.freemarker</groupId>        <artifactId>freemarker</artifactId>        <version>${freemarker.version}</version>    </dependency>    <dependency>        <groupId>org.modelmapper</groupId>        <artifactId>modelmapper</artifactId>        <version>${modelmapper.version}</version>    </dependency>  </dependencies>    <build>    <finalName>testweb1</finalName>  </build></project>

比如我上面加入了幾個依賴:spring、freemarker、modelmapper。

儲存pom.xml,eclipse會自動去到中央伺服器中下載對應的jar包,jar包儲存在使用者檔案夾的./m2下

 

這裡,Maven的eclipse配置基本已經完成了。

 

7、構建和產生Maven

Eclipse中右鍵項目->Run As->Maven install

Maven預設會把產生的war檔案、class所編譯的檔案都放在專案檔夾中的target目錄下

[Maven] - 安裝與Eclipse搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.