Maven安裝與配置,整合Eclipse

1.安裝java jdk
2.下載Maven
安裝到本機
1 將下載回來的包解壓到任意地址,我的路徑是D:\Program Files\apache-maven-3.0.3
2 新建環境變量M2_HOME 指向D:\Program Files\apache-maven-3.0.3
3 在path尾部添加%M2_HOME%\bin
4檢查是否安裝成功
打開cmd
echo %M2_HOME%
mnv –v
如下圖:


插件m2eclipse的安裝
下載插件eclipse-maven3-plugin,http://www.downcc.com/soft/17592.html
解壓到..\MyEclipse 10\dropins


配置本地倉庫
找到maven下的conf 下settings.xml 配置文件,例如:D:\Server\maven\conf\settings.xml
我們程序所需要的jar包等會先去本地倉庫找,如果找不到則會去網絡上的的中央倉庫下載,當然默認本地倉庫是放在c盤用戶下.m2文件夾,這裏我們可以打開.m2的settings.xml進行修改

這裏我們指定本地倉庫位於D盤的MavenRepository文件夾下

配置遠程中央倉庫
方法1:配置/conf/settings.xml
<mirrors>
<mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
  <id>uk</id>
  <name>Human Readable Name for this Mirror.</name>
  <url>http://uk.maven.org/maven2/</url>
  <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
  <id>CN</id>
  <name>OSChina Central</name>
  <url>http://maven.oschina.net/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
  <id>nexus</id>
  <name>internal nexus repository</name>
  <url>http://repo.maven.apache.org/maven2</url>
  <mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

方法2:配置項目pom.xml
<repositories>
           <repository>
                <id>alimaven</id>
                <name>aliyun maven</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>alimaven</id>
                <name>aliyun maven</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                     <enabled>true</enabled>
                </releases>
                <snapshots>
                     <enabled>false</enabled>
                </snapshots>
           </pluginRepository>
</pluginRepositories>

參考資料:
1.Maven基礎-默認中央倉庫[settings.xml 配置詳解]http://blog.csdn.net/yiluoak_47/article/details/12068855/
2.maven如何修改本地倉庫與中央倉庫https://my.oschina.net/ghm7753/blog/373350
3.maven 安裝jar包對應pom.xml的dependency查詢網址:http://mvnrepository.com/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章