Java項目中,當只使用幾個jar包時,很好管理。當使用了好幾十個時,jar包的版本、相互之間的依賴等,管理起來就不是很方便。
Maven最直觀的就是jar包的依賴管理,當然他的使用不僅僅是這些,也不僅僅是使用在Java上。下面是在Eclipse里面整合Maven,
自定義本地倉庫位置,鏡像等。
1、下載Maven,下載地址:http://maven.apache.org/download.cgi
2、下載后,解壓即可
3、復制Maven的bin路徑,添加到環境變量
4、打開高級系統設置
5、添加路徑到環境變量的“Path”,依次點擊”確定“以保存
6、驗證Maven配置,按”Win+r“,打開命令行提示
7、輸入“mvn -v”,驗證
8、編輯Maven的配置文件,“conf”下的“settings.xml”
9、配置本地倉庫位置
10、設置遠程倉庫的鏡像(網速的問題),使用阿里雲鏡像
10.1、代碼1
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> <mirror> <id>nexus-aliyun-thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <name>Nexus aliyun thirdparty</name> <url>http://maven.aliyun.com/nexus/content/repositories/thirdparty/</url> </mirror>
10.2、代碼2
<profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile>
11、打開Eclipse,設置“Preferences”
11、設置Maven選項
11.1、選擇“Maven”的“User Settings”,配置在全局設置
11.2、應用保存后,Eclipse會初始化一下,很快的。這樣就把Maven整合到Eclipse了。用國內鏡像下載,還是很快的。