在Maven中咱们以前进行配置一个项目的依赖时,引用一下jar包,这些jar包第一次都会从一个地方进行下载,这个地方称为仓库,而对于仓库通常有本地仓库和中心仓库之分,可是咱们通常在作项目时会在本身的服务器上配置一个私有仓库,那么咱们下面就来建立一个私有仓库,这里咱们使用的一个工具叫作Nexus。java
一、首先到http://www.sonatype.org/nexus/下载对应的nexus安装包:nexus-latest-bundle.zip浏览器
二、解压缩获得的压缩包,而后将此压缩包中的bin目录(这里为:D:\docs\nexus-latest-bundle\nexus-2.5.1-01\bin)配置到path环境变量中:服务器
三、接着打开cmd,输入nexus:app
这边会让咱们执行start、stop、install、uninstall等命令,咱们首先执行install命令:maven
此时就会提示咱们安装成功了,而且会在系统服务中生成nexus的服务:工具
此时咱们再修改D:\docs\nexus-latest-bundle\nexus-2.5.1-01\bin\jsw\conf,下的wrapper.conf文件,以下:this
1 # Set the JVM executable 2 # (modify this to absolute path if you need a Java that is not on the OS path) 3 wrapper.java.command=java
其中的wrapper.java.command=java修改成本机安装的JDK路径:url
1 # Set the JVM executable 2 # (modify this to absolute path if you need a Java that is not on the OS path) 3 wrapper.java.command=C:\Program Files\Java\jdk1.7.0_17\bin\java
而后执行nexus start命令:spa
四、打开浏览器,输入:http://localhost:8081/nexus就能进行访问了:3d
五、点击右上角的login进行登录:用户名:admin,密码:admin123,登录完成之后就会有不少的命令能够供咱们进行操做了
这里咱们注意观察type属性中的内容:
六、仓库创建完成以后,咱们就能够设置项目引用的仓库了,这里咱们在user-core项目中引用咱们的group仓库:
1 <repositories> 2 <repository> 3 <id>group</id> 4 <name>group repository</name> 5 <url>http://localhost:8081/nexus/content/groups/public/</url> //这里的url咱们能够到nexus的控制面板中找到 6 <releases><enabled>true</enabled></releases> 7 <snapshots><enabled>true</enabled></snapshots> 8 </repository> 9 </repositories>
配置完成之后,咱们user-aggregation项目中随便的加入一个jar包的依赖,这里加入的是commons-io:
1 <dependency> 2 <groupId>commons-io</groupId> 3 <artifactId>commons-io</artifactId> 4 <version>2.4</version> 5 </dependency>
这样咱们能够看到默认的就会到咱们本身的本地仓库进行下载了:
有的时候可能不会出现以上的这种状况,程序可能还会自动的从中央仓库进行下载,这时咱们若是配置其不让从中央仓库下载的话,咱们能够找到maven中的settings文件,而后找到其中的mirrors节点,为咱们的中央仓库配置一下镜像:
1 <mirrors> 2 <!-- mirror 3 | Specifies a repository mirror site to use instead of a given repository. The repository that 4 | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used 5 | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. 6 | 7 <mirror> 8 <id>mirrorId</id> 9 <mirrorOf>repositoryId</mirrorOf> 10 <name>Human Readable Name for this Mirror.</name> 11 <url>http://my.repository.com/repo/path</url> 12 </mirror> 13 --> 14 <mirror> 15 <id>central</id> 16 <mirrorOf>central</mirrorOf> 17 <name>Human Readable Name for this Mirror.</name> 18 <url>http://localhost:8081/nexus/content/groups/public/</url> //为中央仓库设置镜像url,这样当访问中央仓库时不是访问中央仓库的地址,而是咱们配置的镜像地址,也就是咱们本身服务器的地址 19 </mirror> 20 </mirrors>
这样当程序试图访问中央仓库时会自动的转到咱们本身的仓库了。