Maven入門及筆記

  • Maven入門視頻
    此視頻由一個聲音甜美的妹子錄製發佈,具體來源已不可尋,但也要表示感謝。
    百度雲鏈接:http://pan.baidu.com/s/1eSI45W2

  • 入門視頻勘誤及補充

    • Maven實戰(1)
      勘誤
      輸入:mvn archetype:create -DgroupId=com.test.maven -DartifactId=test1
      報錯: Build failure.
      原因: create已被棄用,現在要用generate。

      補充
      設置Maven倉庫鏡像
      前提:設置好環境變量,輸入mvn -v返回正確信息。
      視頻中說到,解壓縮後的“apache-maven-3.3.9\conf”文件夾中的setting.xml是全局的設置文件。我們要讓設置在單個用戶下生效,就要在"C:\Users\[以你用戶名命名的文件夾]"下創建“.m2”文件夾。
      創建“.m2”時,電腦會提示“需鍵入文件名”。這裏有個小技巧,就是創建時輸入“.m2.”,注意2後面加上“.”,然後回車,電腦就不會報錯了。
      然後把“apache-maven-3.3.9\conf”下的setting.xml複製到.m2文件夾中,打開setting.xml來設置Maven倉庫鏡像。
      爲什麼要設置倉庫鏡像呢?
      因爲Maven默認是從https://repo.maven.apache.org/maven2這個遠程中央倉庫上下載需要的包,第一次創建工程需要下載大量的包,如果發生了連接這個默認的中央倉庫下載速度慢,經常還下不動得情況,可以通過設置連接國內的倉庫鏡像看看能不能解決這個問題。
      就我個人的體驗,一開始從默認的倉庫下會斷斷續續,但運氣好終於是下完了,換成國內的倉庫鏡像並沒有很好地解決下載速度的問題。

      maven倉庫鏡像地址推薦
      http://blog.csdn.net/zuoluoboy/article/details/20007819
      建議在設置之前,用瀏覽器打開一下網頁,能打開的地址才能下載。

      打開.m2下的setting.xml(我使用的UltraEdit),找到Mirror項。
      這時要注意,xml中的所有子項都是被註釋化的,就跟編程時的註釋一樣,只是文本。我們要做的,一是把Mirror的選項填寫正確,二是把Mirror選項去註釋化。
      原來的樣子

<!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <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.
     |    A1位置
       <mirror>
          <id>mirrorId</id>    Step2:鍵入鏡像的參數。
          <mirrorOf>repositoryId</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>
    </mirror>
     --> Step1:剪切這一行,粘貼到A1位置。
</mirrors>


              我使用的UltraEdit打開,修改後可以看到文字的顏色改變了,這個時候保存修改,再接着看視頻,創建項目時就自動從新的地址下載包了,如果下載速度不行,就再換其他的地址。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章