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打开,修改后可以看到文字的颜色改变了,这个时候保存修改,再接着看视频,创建项目时就自动从新的地址下载包了,如果下载速度不行,就再换其他的地址。



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