---
title: "Nexus创建本地Maven仓库"
author: "yzyzero"
date: "2014-09-22T10:58:07Z"
tags: []
categories: ["开源软件"]
slug: "nexus-maven"
draft: false
lastmod: "2014-09-22T10:58:07Z"
id: 2119063
url: "https://yzyzero.iteye.com/blog/2119063"
---

# 0.安装环境

windows 7 x86-64

jdk1.6.0\_27 32-bit（假定该环境中已经设置了jdk的环境变量）

maven 3.1.1

nexus-2.9.1-02-bundle

 

# []()1.安装maven3.1.1

1）下载maven

访问maven官方网站[http://maven.apache.org/](http://maven.apache.org/)，下载maven包。下载链接为：[http://apache.fayea.com/apache-mirror/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip](http://apache.fayea.com/apache-mirror/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip)

2）解压下载到的apache-maven-3.1.1-bin.zip到某个目录。（如E:\\Eb\\Apache Software Foundation\\apache-maven-3.1.1）

3）设置环境变量。

第一，添加用户变量M2\_HOME（实际应为M3\_HOME，懒得改了，下面都用M2\_吧），M2\_HOME=E:\\Eb\\Apache Software Foundation\\apache-maven-3.1.1

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211539390?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

第二，添加用户变量M2，M2=%M2\_HOME%\\bin

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211559437?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

第三，修改用户变量PATH（若没有此变量，则添加一个），PATH=%M2%;%PATH%

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211802346?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

4）验证maven是否安装成功。打开命令行，输入mvn -v，显示如下信息即为安装成功。

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211810380?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

# []()2.安装nexus

1）下载nexus

访问nexus官方网站[http://www.sonatype.org/nexus/](http://www.sonatype.org/nexus/)，下载nexus-2.9.1-02-bundle.zip。 [http://www.sonatype.org/nexus/archived](http://www.sonatype.org/nexus/archived)

2）解压至某个目录（如E:\\Eb\\nexus-2.9.1-02-bundle）

3）开启jetty服务器。找到E:\\Eb\\nexus-2.9.1-02-bundle\\nexus-2.9.1-02\\bin\\jsw\\windows-x86-32（由于jdk安装的是32位版本，因此执行此目录下的文件）目录，执行console-nexus.bat批处理文件，等待命令行执行到如下情况：

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211857118?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

不要关闭命令行窗口。

4）访问nexus管理页面。

打开浏览器，输入http://localhost:8081/nexus/，点击页面右上方的Log in超链接，输入默认用户名密码admin/admin123，登录nexus管理页面。

# []()3.配置nexus

1）登录nexus管理页面，点击左侧的Repositories，显示相关的仓库信息，各个仓库的含义可自行百度之。

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921211927881?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

2）修改默认的存储路径。

安装nexus后，本地仓库默认的jar包存储位置是file:/E:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus/storage/central。由于Central仓库占用存储较大，我们可以单独设置其存储位置。

首先，将E:/Eb/nexus-2.9.1-02-bundle/sonatype-work/目录下的所有内容复制到H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/目录下；

第二，选中Central，打开Configuration选项卡，修改Override Local Storage Location项的值为file:/H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus/storage/central，点击页面下方的save按钮。

3）同步索引。

首先，选中Central，点击下方的Configuration选项卡。修改Download Remote Indexes项的值为True。点击页面下方的save按钮。

第二，右键点击Central，弹出菜单中点击Repair Index。

修改完成后的配置如下图：

![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://blog.csdn.net/kingzone_2008/article/details/39454873)![](http://img.blog.csdn.net/20140921212000220?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQva2luZ3pvbmVfMjAwOA=%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast)

4）Apache Snapshots和Codehaus Snapshots两个仓库也按照上述1）2）3）步骤修改，只是Override Local Storage Location项分别为file:/H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus/storage/apache-snapshots和file:/H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus/storage/codehaus-snapshots

# []()4.配置maven使用nexus

1）在maven安装目录中找到maven的全局配置文件。E:\\Eb\\Apache Software Foundation\\apache-maven-3.1.1\\conf目录下的settings.xml文件。

2）将settings.xml修改为如下配置：

 

**\[html]** [view plain](http://blog.csdn.net/kingzone_2008/article/details/39454873 "view plain")[copy](http://blog.csdn.net/kingzone_2008/article/details/39454873 "copy")[![在CODE上查看代码片](https://code.csdn.net/assets/CODE_ico.png)](https://code.csdn.net/snippets/472608 "在CODE上查看代码片")[![派生到我的代码片](https://code.csdn.net/assets/ico_fork.svg)](https://code.csdn.net/snippets/472608/fork "派生到我的代码片")

 

001. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
002. &lt;settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
003. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
004. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"&gt;
005. &lt;localRepository&gt;E:/.m2/repository&lt;/localRepository&gt;
006. &lt;pluginGroups&gt;
007. &lt;/pluginGroups&gt;
008. &lt;!-- proxies
009. | This is a list of proxies which can be used on this machine to connect to the network.
010. | Unless otherwise specified (by system property or command-line switch), the first proxy
011. | specification in this list marked as active will be used.
012. |--&gt;
013. &lt;proxies&gt;
014. &lt;!-- proxy
015. | Specification for one proxy, to be used in connecting to the network.
016. |
017. &lt;proxy&gt;
018. &lt;id&gt;optional&lt;/id&gt;
019. &lt;active&gt;true&lt;/active&gt;
020. &lt;protocol&gt;http&lt;/protocol&gt;
021. &lt;username&gt;proxyuser&lt;/username&gt;
022. &lt;password&gt;proxypass&lt;/password&gt;
023. &lt;host&gt;proxy.host.net&lt;/host&gt;
024. &lt;port&gt;80&lt;/port&gt;
025. &lt;nonProxyHosts&gt;local.net|some.host.com&lt;/nonProxyHosts&gt;
026. &lt;/proxy&gt;
027. --&gt;
028. &lt;/proxies&gt;
029. &lt;!-- servers
030. | This is a list of authentication profiles, keyed by the server-id used within the system.
031. | Authentication profiles can be used whenever maven must make a connection to a remote server.
032. |--&gt;
033. &lt;servers&gt;
034. &lt;/servers&gt;
035. &lt;!-- mirrors
036. | This is a list of mirrors to be used in downloading artifacts from remote repositories.
037. |
038. | It works like this: a POM may declare a repository to use in resolving certain artifacts.
039. | However, this repository may have problems with heavy traffic at times, so people have mirrored
040. | it to several places.
041. |
042. | That repository definition will have a unique id, so we can create a mirror reference for that
043. | repository, to be used as an alternate download site. The mirror site will be the preferred
044. | server for that repository.
045. |--&gt;
046. &lt;mirrors&gt;
047. &lt;mirror&gt;
048. &lt;!--This is used to direct the public snapshots repo in the
049. profile below over to a different nexus group --&gt;
050. &lt;id&gt;nexus-public-snapshots&lt;/id&gt;
051. &lt;mirrorOf&gt;public-snapshots&lt;/mirrorOf&gt;
052. &lt;url&gt;http://localhost:8081/nexus/content/groups/public-snapshots&lt;/url&gt;
053. &lt;/mirror&gt;
054. &lt;mirror&gt;
055. &lt;!--This sends everything else to /public --&gt;
056. &lt;id&gt;nexus&lt;/id&gt;
057. &lt;mirrorOf&gt;\*&lt;/mirrorOf&gt;
058. &lt;url&gt;http://localhost:8081/nexus/content/groups/public&lt;/url&gt;
059. &lt;/mirror&gt;
060. &lt;/mirrors&gt;
061. &lt;profiles&gt;
062. &lt;profile&gt;
063. &lt;id&gt;development&lt;/id&gt;
064. &lt;repositories&gt;
065. &lt;repository&gt;
066. &lt;id&gt;central&lt;/id&gt;
067. &lt;url&gt;http://central&lt;/url&gt;
068. &lt;releases&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/releases&gt;
069. &lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt;
070. &lt;/repository&gt;
071. &lt;/repositories&gt;
072. &lt;pluginRepositories&gt;
073. &lt;pluginRepository&gt;
074. &lt;id&gt;central&lt;/id&gt;
075. &lt;url&gt;http://central&lt;/url&gt;
076. &lt;releases&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/releases&gt;
077. &lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt;
078. &lt;/pluginRepository&gt;
079. &lt;/pluginRepositories&gt;
080. &lt;/profile&gt;
081. &lt;profile&gt;
082. &lt;!--this profile will allow snapshots to be searched when activated--&gt;
083. &lt;id&gt;public-snapshots&lt;/id&gt;
084. &lt;repositories&gt;
085. &lt;repository&gt;
086. &lt;id&gt;public-snapshots&lt;/id&gt;
087. &lt;url&gt;http://public-snapshots&lt;/url&gt;
088. &lt;releases&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;/releases&gt;
089. &lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt;
090. &lt;/repository&gt;
091. &lt;/repositories&gt;
092. &lt;pluginRepositories&gt;
093. &lt;pluginRepository&gt;
094. &lt;id&gt;public-snapshots&lt;/id&gt;
095. &lt;url&gt;http://public-snapshots&lt;/url&gt;
096. &lt;releases&gt;&lt;enabled&gt;false&lt;/enabled&gt;&lt;/releases&gt;
097. &lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt;
098. &lt;/pluginRepository&gt;
099. &lt;/pluginRepositories&gt;
100. &lt;/profile&gt;
101. &lt;/profiles&gt;
102. &lt;!-- activeProfiles
103. | List of profiles that are active for all builds.
104. |
105. &lt;activeProfiles&gt;
106. &lt;activeProfile&gt;alwaysActiveProfile&lt;/activeProfile&gt;
107. &lt;activeProfile&gt;anotherAlwaysActiveProfile&lt;/activeProfile&gt;
108. &lt;/activeProfiles&gt;
109. --&gt;
110. &lt;activeProfiles&gt;
111. &lt;activeProfile&gt;development&lt;/activeProfile&gt;
112. &lt;/activeProfiles&gt;
113. &lt;/settings&gt;

3）验证是否设置成功。

 

打开命令行，执行如下语句：

 

**\[plain]** [view plain](http://blog.csdn.net/kingzone_2008/article/details/39454873 "view plain")[copy](http://blog.csdn.net/kingzone_2008/article/details/39454873 "copy")[![在CODE上查看代码片](https://code.csdn.net/assets/CODE_ico.png)](https://code.csdn.net/snippets/472608 "在CODE上查看代码片")[![派生到我的代码片](https://code.csdn.net/assets/ico_fork.svg)](https://code.csdn.net/snippets/472608/fork "派生到我的代码片")

 

1. mvn help:system

之后，查看E:/.m2/repository（&lt;localRepository&gt;E:/.m2/repository&lt;/localRepository&gt;将maven的默认配置改为该目录，默认配置为C:\\Users\\&lt;用户名&gt;\\.m2\\repository）和file:/H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus/storage/central两个目录下都有了新下载到的jar包。则表示配置成功。