maven使用总结

2017-12-19  本文已影响0人  writeanewworld

1.学会使用工具
在以后的学习工作中会遇到各种各样的工具,要学会使用各种各样的工具。其实基本的操作都是一样的,像intellij IDEA、Spring STS、eclipse

2.maven的使用
1) 首先下载一个已经集成了maven的eclipse。这样就不必自己集成了,因为自己集成这个东西跑崩过电脑。
2) 然后下载maven压缩包,解压到本地一个目录,记住目录名
3)配置环境变量
新建 M2_HOME 下放你的本地maven路径,我的是F:\maven\apache-maven-3.5.2-bin\apache-maven-3.5.2
path中添加 %M2_HOME%\bin windows10系统。

然后cmd测试一下:这样就好了


image.png

4)在eclipse中配置你自己的maven
windows->preference->maven->installations->add 添加你自己本地的maven


image.png

3.新建项目

1)新建一个maven java项目或者一个maven web项目。


image.png

4.maven简介
在开发一个项目中往往需要大量的jar包,自己受用手动导入会异常的麻烦。所以使用maven进行jar包的管理。
jar包是在maven仓库中通过pom.xml中的关系来对应下载的,不需要手动添加jar

5.添加国内镜像仓库
由于使用的是国外的maven仓库,下载会很慢,所以需要自己配置使用镜像仓库,就是在本地文件conf中找到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>
<mirror>
    <id>central</id>
    <name>Maven Repository Switchboard</name>
    <url>http://repo1.maven.org/maven2/</url >
    <mirrorOf>central</mirrorOf>
</mirror>
<mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url >
</mirror>
<mirror>
    <id>ibiblio</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url >
</mirror>
<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url >
</mirror>
<!-- 中央仓库在中国的镜像 -->
<mirror>
    <id>maven.net.cn 
</id>
    <name>oneof the central mirrors in china</name>
    <url>http://maven.net.cn/content/groups/public/</url >
    <mirrorOf>central</mirrorOf>
</mirror>

<!-- 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>

6.更改maven仓库的本地位置
这个稍微有一点麻烦

首先将本地maven中的setting.xml添加一条:
<localRepository>E:\maven-repository\repository</localRepository>
并copy到你的新仓库位置。然后环境变量不用管。(环境变量可以在版本升级中使用到)
然后将eclipse中maven指向新的setting.xml


image.png

cmd验证测试:


image.png

不验证也没事,好使就行。

然后右击项目->maven->update project就可以下载替换jar到新仓库中。

上一篇 下一篇

猜你喜欢

热点阅读