記錄爲了自己方便。
1. Maven 安裝
下載,找個合適的包: http://maven.apache.org/download.cgi。 解壓就可以了,不用再安裝。
如我的路徑: D:\java\maven\apache-maven-3.1.1 (去年了帶bin 的文件夾)
2. Maven 配置
[Maven is a Java tool, so you must have Java installed in order to proceed. More precisely, you need a Java Development Kit (JDK), the Java Runtime Environment (JRE) is not sufficient.] => 使用maven 前需確保Java, JDK 已安裝。
2.1 環境變量
a, 在系統變量里加一項:M2_HOME
b. 系統變量的Path 里加入:%M2_HOME%\bin
我自己的win7 系統用b 中變量不管用,所以把maven 中bin 的全路徑給加進去:D:\java\maven\apache-maven-3.1.1\bin
2.2 maven 的配置文件
下面貼原文:
There are two locations where a settings.xml file may live:
- The Maven install: $M2_HOME/conf/settings.xml
- A user's install: ${user.home}/.m2/settings.xml
The former settings.xml are also called global settings, the latter settings.xml are referred to as user settings. If both files exists, their contents gets merged, with the user-specific settings.xml being dominant. => 第一個文件是全局的,第二個是局部的,兩個設置文件的設置疊加工作,衝突則以第二個爲主。
Tip: If you need to create user-specific settings from scratch, it's easiest to copy the global settings from your Maven installation to your ${user.home}/.m2 directory. Maven's default settings.xml is a template with comments and examples so you can quickly tweak it to match your needs. => 所以想要定製一些設置,則把該文件從第一個地方複製到第二個地方。然後再去改。
挺多設置可以改的,具體看官方介紹:http://maven.apache.org/settings.html
有一個叫localRepository的,這個是指定maven 將下載的依賴包的放置的地方。
3. Maven 在eclipse 中的插件
安裝: Help -> Install New Software -> Add => e2eclipse/http://download.eclipse.org/technology/m2e/releases
4. M2E-Android
[The Android Configurator is an Maven Integration for Eclipse (m2e) plug-in that adds maven support for Android Developer Tools (ADT) and the Maven Android Plugin. It brings the power of Maven dependency management into the ADT.]
Install:
You will need Eclipse Indigo or Juno installed. Help -> Eclipse Marketplace... -> install plug-in and its dependencies -> finish
5. 建立Maven的project
File--new—other—Java Maven Project
6. 應用Maven來打包Project
在cmd中的命令:
a. mvn eclipse:clean 清除Project中以前的編譯的東西,重新再來
b. mvn eclipse:eclipse 開始編譯Maven的Project
在Myeclipse中的操作:
a. 選中Maven Project 右擊 在Run As中選擇Maven clean
b. 在Myeclipse中,Project—Clean 開始編譯
c. 選中Maven Project 右擊 在Run As中選擇Maven install
執行完這幾步,如果沒發生異常,會在project裏生成一個target文件夾,這個文件夾裏的東西,就是Maven爲你打包發佈的東西。
參考:
http://www.cnblogs.com/good_hans/archive/2010/03/22/1691965.html