1. 安裝
在http://maven.apache.org/download.html 中下載最新版本
解壓縮, 並且正確設置環境變量
具體操作如官方說明一樣:
Windows 2000/XP
- Unzip apache-maven-2.0.8-bin.zip to the directory you wish to install Maven 2.0.8. These instructions assume you chose C:/Program Files/Apache Software Foundation/apache-maven-2.0.8
- Add the bin directory to your path, by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then editing the PATH variable in the user variables. eg. "C:/Program Files/Apache Software Foundation/apache-maven-2.0.8/bin";%PATH%
- In the same dialog, make sure that JAVA_HOME is set to the location of your JDK, eg. C:/Program Files/Java/jdk1.5.0_02
- Run mvn --version to verify that it is correctly installed.
Unix-based Operating Systems (Linux, Solaris and Mac OS X)
- Extract the distribution archive to the directory you wish to install Maven 2.0.8. These instructions assume you chose /usr/local/apache-maven-2.0.8 . The directory apache-maven-2.0.8 will be created from the archive.
- Add the bin directory to your path, eg. export PATH=/usr/local/apache-maven-2.0.8/bin:$PATH
- Make sure that JAVA_HOME is set to the location of your JDK, eg. export JAVA_HOME=/usr/java/jdk1.5.0_02
- Run mvn --version to verify that it is correctly installed.
2.生成Maven項目
生成標準佈局的webapp項目,在控制檯執行下面命令(groupId後面是包名,artifactId後面是項目名稱):
mvn archetype:create -DgroupId=net.jeffrey
-DartifactId=my-webapp
-DarchetypeArtifactId=maven-archetype-webapp
生成標準佈局的普通java項目,執行:
mvn archetype:create -DgroupId=net.jeffrey -DartifactId=my-app
完成後你會看到已經生成了一個名爲my-webapp的文件夾,這就是剛剛生成好的項目目錄
在my-webapp根目錄下,你會看到名爲pom.xml的文件,這個就是maven的項目描述文件
3.maven和eclipse整合
安裝maven2插件 http://m2eclipse.codehaus.org/
網站中有詳細的FLASH DEMO介紹安裝和基本使用
4.架設artifactory私服管理
直接下載解壓就可以使用
項目的pom.xml文件修改
具體的依賴寫法,要參考 http://mvnrepository.com/
簡要步驟如下:
0. 爲eclipse添加Maven2和MyEclipse插件
1. 將Maven項目轉爲Eclipse項目,具體操作爲將dos命令窗口切換到Maven項目的目錄下,輸入命令: mvn eclipse:eclipse
2. 進入eclipse,將這個項目導入工作空間
3. 在該項目上點右鍵Maven->Enable
4. 在該項目上點右鍵Build Path->Configure Build Path->Java Build Path->Libraries->去掉Maven添加的變量路徑
5. 在該項目上點右鍵MyEclipse->Add Web Capabilities->修改Web root地址(點【瀏覽】按鈕指定爲當前工作空間下的src/main/webapp文件夾)