Nexus下载地址:https://www.sonatype.com/download-oss-sonatype

选择相应的版本下载后,本人下载的是nexus-2.12.0-01-bundle.zip版本。nexus默认是和jetty集成的,如果要在Tomcat环境下使用,则按照如下步骤进行配置即可:

 

1,解压文件后后得到两个文件夹,[nexus-2.12.0-01]及[sonatype-work],[nexus-2.12.0-01]文件夹看到他的结构类似于Tomcat服务器。

将这两个文件夹复制到一个目录下,可以不用在Tomcat的webapps目录下也行。本人是在webapps下面创建了一个Nexus的文件夹,并将这两个文件复制到里面,如:F:\Tomcat8\apache-tomcat-8.5.9\webapps\Nexus。

2.把nexus-2.12.0-01\lib文件夹下面的除了javax.servlet*.jar及jetty*jar的所有jar包文件复制到nexus-2.12.0-01\nexus\WEB-INF\lib下面。

3.修改nexus-2.12.0-01\nexus\WEB-INF\classes\nexus.properties文件修改:nexus-work=F:/Tomcat8/apache-tomcat-8.5.9/webapps/Nexus/sonatype-work/nexus,注意斜杆的方向。

4.修改Tomcat的server.xml文件,在Host节点内添加Context节点,修改后如下:

1
2
3
4
5
6
7
8
9
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
 
        <Context docBase="F:\Tomcat8\apache-tomcat-8.5.9\webapps\Nexus\nexus-2.12.0-01\nexus" path="/nexus" reloadable="true"/>
 
      </Host>

启动Tomcat,在浏览器打开地址http://localhost/nexus,我用的是80端口,成功了。

 5.修改本地的Maven配置文件内容

找到用户的.m2/setting.xml文件,也可以在Eclipse的Preferences->Maven->User Settings->User Settings内找到。

打开此文件,在此文件内添加本地的Maven仓库目录,如:

<localRepository>F:\Maven\MavenRepository</localRepository>

添加Maven镜像仓库位置:

1
2
3
4
5
6
7
8
9
10
<mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://localhost/nexus/content/groups/public/</url>
 </mirror>
<mirror>
    <id>snapshots</id>
    <mirrorOf>snapshots</mirrorOf>
    <url>http://localhost/nexus/content/repositories/snapshots/</url>
</mirror>

配置Profile及激活Profile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<profile>  
      <id>development</id>  
      <repositories>  
            <repository>  
                <id>central</id>                                     
                <url>http://localhost/nexus/content/groups/public/</url>       
                <releases>  
                    <enabled>true</enabled>  
                </releases>  
                <snapshots>  
                    <enabled>true</enabled>  
                </snapshots>  
            </repository>  
        </repositories>     
         <pluginRepositories>  
            <pluginRepository>  
              <id>central</id>  
              <url>http://localhost/nexus/content/groups/public/</url>
              <releases>  
                <enabled>true</enabled>  
              </releases>  
              <snapshots>  
                <enabled>false</enabled>  
              </snapshots>  
            </pluginRepository>  
        </pluginRepositories>  
    </profile> 
 
  </profiles>
  <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>

添加认证信息,填写正确的用户名密码

1
2
3
4
5
6
7
8
9
10
<server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin</password>
 </server>

  

6.构建项目并部署到Nexus仓库,修改pom文件(自动部署),这里到底是部署到release仓库还是snapshots,具体还要看项目的version的后缀是snapshots还是release。

1
2
3
4
5
6
7
8
9
10
11
<!-- 自动部署构件到Nexus仓库 -->
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <url>http://localhost/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://localhost/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

执行命令:mvn clean deploy  部署到Nexus仓库内。

最终部署到Nexus仓库效果如下,项目的version为0.0.1-RELEASE