使用JAVA工程管理越來越多的jar包,擔心導錯了,多導了,漏導了怎么辦?
換一個IDE項目后項目會不會出一堆BUG,看的頭皮發麻?
自己寫的代碼放在別人的機器上運行會不會出問題?
Maven的強大毋庸置疑,當使用Maven后以上這些都不是問題,但是配置maven是一件耐心的事情,基本步驟總結如下:
一、下載
http://maven.apache.org/download.cgi
也可以直接在eclipse工具中下載,點擊eclipse菜單欄Help->Eclipse Marketplace搜索關鍵字maven到插件Maven Integration for Eclipse 並點擊安裝即可
架構Maven工作環境(配置環境變量)
新建:MAVEN_HOME
路徑(例如):D:\360Downloads\tools\marven3.5\apache-maven-3.5.0
添加到path配置文件中:;%MAVEN_HOME%\bin;
二、配置好后驗證
輸入mvn -version
成功后會有如以下提示:
Microsoft Windows [版本 6.1.7601]
版權所有 (c) 2009 Microsoft Corporation。保留所有權利。
C:\Users\Administrator>mvn -version
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:0
6+08:00)
Maven home: D:\360Downloads\tools\marven3.5\apache-maven-3.5.0-bin\apache-maven-
3.5.0\bin\..
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: D:\Program Files\Java\jdk1.8.0_121\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
三、修改默認下載地址,默認下載地址在C盤中如下:
C:\Users\Administrator\.m2
建議換一個地址,防止系統變慢,重裝系統也不會影響。
如:D:\eee\1701javaee_2\maveninport_aliyun\.m2
四、將安裝路徑下的apache-maven-3.5.0\conf\settings.xml文件復制一份到新地址的.m2目錄下面(與repository在同一目錄)。
五、打開eclipse將Maven工程添加到eclipse工具中。
window->preferences->maven->installations->add->maven安裝路徑。
六、打開settings.xml,修改如下2個地方的內容:
1、此處為存放下載依賴存放地方,在文件第53行:
原始文件:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
修改后的文件:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\eee\1701javaee_2\maveninport_aliyun\.m2\repository</localRepository>
2、此處為修改為從阿里雲服務器上下載依賴,強烈建議更換,下載速度會快很多,在文件第160行
原始文件:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>
修改后的文件:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<!-- 阿里雲鏡像 下載配置 -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!-- 另一個備用模板 -->
<!-- <mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>-->
</mirrors>
完成后重啟eclipse.