- 類(lèi)型:編程工具大。13.8M語(yǔ)言:英文 評(píng)分:5.5
- 標(biāo)簽:
簡(jiǎn)單講下maven的安裝步驟:
1.在安裝maven之前,先確保已經(jīng)安裝JDK1.6及以上版本,并且配置好環(huán)境變量。
2.下載maven3,最新版本是Maven3.0.4 ,下載地址:http://maven.apache.org/download.html
下載apache-maven-3.0.4-bin.zip文件后,并解壓到 D:\cloud_cms\maven\apache-maven-3.0.4
3.配置maven3的環(huán)境變量:先配置M2_HOME的環(huán)境變量,新建一個(gè)系統(tǒng)變量:M2_HOME , 路徑是:D:\cloud_cms\maven\apache-maven-3.0.4,如圖所示:
再配置path環(huán)境變量,在path值的末尾添加"%M2_HOME%\bin",如下圖所示;
5.點(diǎn)擊確定之后,打開(kāi)cmd窗口:輸入 mvn -version,出現(xiàn)如下內(nèi)容表示安裝成功。
1:環(huán)境
eclipse indigo,
JDK1.6,
maven 3.2.1,
tomcat7.0.42
2:安裝eclipse maven插件 m2eclipse
第一種方法:從網(wǎng)上下載m2eclipse,這個(gè)網(wǎng)上有很多下載的地方。然后放到eclipse安裝目錄的plugins下。
第二種方法:打開(kāi)eclipse->help->install new software。在work with后輸入:http://download.eclipse.org/technology/m2e/releases。如圖:
3:下載maven和tomcat
上apache官網(wǎng)下載maven:http://maven.apache.org/download.cgi。下載完成后解壓即可。
上apache官網(wǎng)下載tomcat:http://tomcat.apache.org/。
4:eclipse配置maven
window-》prefrences-》maven-》user setting。如圖
window-》prefrences-》maven-》installations。如圖
5:配置tomcat和maven
進(jìn)入tomcat_home/conf/tomcat_users.xml:修改如下:
[html]
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
進(jìn)入maven_home/conf/settings.xml:修改如下:
[html]
<server>
<id>tomcat</id>
<username>admin</username>
<password>admin</password>
</server>
6:eclipse創(chuàng)建maven web項(xiàng)目
這個(gè)簡(jiǎn)單,new-》other-》maven project-》next。這里注意groupid選org.apache.maven.archetypes ,artifactid 選maven-archetype-webapp,然后next,輸入我們自己的groupid(com.test),artifactid(transition),然后finish,OK。如圖所示:
7:修改pom.xml
[html]
<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.test</groupId>
<artifactId>transition</artifactId>
<packaging>war</packaging>
<version>0.0.1</version>
<name>transition Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>maven_remote_1</id>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>transition</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<warFile>target/transition.war</warFile>
<server>tomcat</server>
<url>http://localhost:8080/manager/text</url>
<path>/transition</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
8:運(yùn)行maven項(xiàng)目
先進(jìn)入tomcat目錄啟動(dòng)tomcat,然后右鍵項(xiàng)目 run as-》run configrations:
Goals項(xiàng)輸入:package tomcat:redeploy
Maven Runtime選擇我們自己的maven。如圖:
然后點(diǎn)Run,控制臺(tái)顯示如下:
[plain]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\transition\src\main\webapp]
[INFO] Webapp assembled in [3 msecs]
[INFO] Building war: E:\transition\target\transition.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition ---
[INFO] Deploying war to http://localhost:8080/transition
[INFO] OK - Undeployed application at context path /transition
[INFO] OK - Deployed application at context path /transition
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.412 s
[INFO] Finished at: 2014-03-13T11:43:42+08:00
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
這里省略很多控制臺(tái)輸出,出現(xiàn)BUILD SUCCESS 則說(shuō)明部署成功,瀏覽器輸入:http://localhost:8080/transition/。顯示Hello world..
注意:這樣成功之后項(xiàng)目會(huì)直接打成war包,部署到tomcat下,每次build不需要重啟tomcat。這樣致命的缺點(diǎn)就是,不能調(diào)試。如果需要調(diào)試且在eclipse中啟動(dòng)tomcat的話(huà)。會(huì)發(fā)現(xiàn)右鍵項(xiàng)目沒(méi)有run as server,有兩種方法解決:
第一種:這時(shí)需要把項(xiàng)目轉(zhuǎn)變成dynamic web module。右鍵項(xiàng)目-》properties-》project facets,然后右邊選中dynamic web module。之后就會(huì)出現(xiàn)run as server了.
第二種:右鍵項(xiàng)目,run/debug as configrations 如上第8步驟的圖。不過(guò)Goals中天上【tomcat:run】。然后run就OK了,注意這里不需要提前啟動(dòng)tomcat。