1. 程式人生 > >新手配置Maven

新手配置Maven

1.下載解壓apache-maven-3.5.4-bin.zip到一個全英文無空格路徑。我把它解壓到D:\java這個路徑中

(下載地址:http://maven.apache.org/download.cgi)   點選開啟連結



2.配置環境變數,在path中新增maven的bin路徑,如D:\java\apache-maven-3.5.4\bin


3.在maven主目錄中新建資料夾,重新命名為repositorys





4.在maven主目錄中的conf目錄中找到setting.xml檔案

在<settings>標籤下面新增標籤(指明repositorys資料夾的路徑):<localRepository>D:\java\apache-maven-3.5.4\repositorys</localRepository>


然後在<mirrors>標籤中新增阿里雲映象:
       <mirror>
            <id>nexus-aliyun</id>
            <mirrorOf>*</mirrorOf>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>

        </mirror>




5.進入bin目錄中,在位址列中輸入cmd開啟命令列視窗(或在bin資料夾中的空白處:Shift+右鍵->在此處開啟命令視窗)。輸入:mvn help:system,等待系統自動下載檔案,直到出現“BUILD SUCCESS”則完成





後續:在Eclipse中配置Maven

1.在eclipse中的perference中選Maven選項,在Installation中新增mavan的主目錄。


然後在User Settings中的User Settings中新增conf資料夾中的setting.xml檔案。




2.新建maven專案,在http://mvnrepository.com/中找到你要匯入的jar包,把對應的<dependency>標籤填寫到pom.xml檔案中。

例如,我想新增MySQL的驅動jar包:


============================================================================


=========================================================================


=======================================================



系統自動匯入jar包,如果是初次使用,匯入的jar包是空的(沒有原始碼),這就無法使用。


解決方法:右鍵點選專案,在Maven選項中選擇“Download Sources”

奶瓶圖示變了?多了張紙?是的話就已經導包完成,你已經學會在Eclipse中建立Maven專案了。