Maven安裝教程

下載

Maven 是 Apache 軟件基金會組織維護的一款自動化構建工具, 專注服務於 Java 平臺的項目構建和依賴管理。 Maven 這個單詞的本意是: 專家,內行。 讀音是[‘meɪv(ə)n]或[‘mevn]。

maven下載地址

  • 點擊下載地址,如下所示:
    點擊下載

  • 解壓maven的壓縮包到相應的硬盤中(比如D盤下)

設置環境變量

  • 複製環境變量路徑image
  • 右鍵我的電腦->屬性->高級系統設置->環境變量->Path
    設置Path
  • 添加Maven的lib路徑
    image
  • 檢查Maven的版本及是否安裝成功,進入windows的cmd輸入mvn -v
    image

更改seting.xml文件

  • setting.xml文件在maven安裝目錄的conf文件下
  • 設置本地廠庫的路徑
    使用文本編輯器打開setting.xml文件,找到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>
  -->

由這段代碼可知,maven的默認路徑爲~.m2\repository,我們可以選擇默認,本人覺得還是修改成自己的路徑尾爲好(我的本地廠庫的路徑F:/maven/repo)。修改代碼爲:


<!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
   -->
  <localRepository>F:/maven/repo</localRepository>
  • 設置默認jdk版本
    在setting.xml文件中找到profiles節點,在節點下填寫如下代碼:

    <!--設置默認的jdk版本-->

    <profile>
        <id>jdk-1.7</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.7</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
            <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
        </properties>
    </profile>
  • 設置maven的鏡像地址
    同樣是maven的setting.xml文件中找到mirrors節點,在節點下填入如下代碼

<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>   
</mirror>

maven的默認鏡像地址是國外的,由於在國內被牆的原因,使得項目在使用maven編譯時好多依賴下載不下來,所以修改鏡像地址爲阿里雲的maven依賴,這樣便可保證項目依賴的穩定性

修改好的seting.xml文件

文件的下載地址setting.xml文件

發佈了46 篇原創文章 · 獲贊 14 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章