Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

首先下载nexus安装包,我这里使用的是nexus-2.11.2-03-bundle.tar.gz(下载地址:http://www.sonatype.org/nexus/go/)

演示将会安装在/root/tengjs目录下

将安装包拷贝到/root/tengjs目录下

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

创建nexus目录,用来放置解压后的文件

# mkdir nexus

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

将安装包解压到nexus目录下

# tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C nexus

解压完成后会看到在nexus目录下有两个文件

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

nexus-2.11.2-03(nexus服务)

sonatype-work(私有库目录)

进入nexus-2.11.2-03/conf目录

编辑nexus.properties文件

# vim nexus.properties

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

这里默认的是8081端口,因为我的8081端口已被使用,所以这里改为8082

编辑nexus脚本,配置RUN_AS_USER参数

# cd /root/tengjs/nexus/nexus-2.11.2-03/bin

# vim nexus

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

RUN_AS_USER=改为RUN_AS_USER=root

防火墙打开8082端口

# vim /etc/sysconfig/iptables

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

保存后重启防火墙

# service iptables restart

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

阿里云服务器添加入方向安全组规则

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

启动nexus

# /root/tengjs/nexus/nexus-2.11.2-03/bin/nexus start

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

ok,启动成功

浏览器中打开

http://xxx.xxx.xxx.xxx:8082/nexus

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

右上角登录,默认用户名为admin,默认密码为admin123

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

 到此,nexus已经安装完成了,接下来是nexus的配置

菜单Administration/Server配置邮箱服务地址(如果忘记密码,可以通过该邮箱找回密码)

我这里使用的是qq邮箱

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

点击Test SMTP settings测试

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

刚开始我这里一直发送不出去,最后发现特么qq邮箱没有开通smtp服务

进入qq邮箱,设置 > 账户 > POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

设置完成后再次测试,注意密码框里填写的不是qq的密码,是你开通smtp服务时qq给你的授权码

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

 

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

ok,发送成功,点击保存

给用户配置邮箱地址

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

改成我自己的邮箱地址

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

现在测试一下

假如你忘记了密码

登录时点击password

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

填写完成后点击Reset Password,就会收到邮件

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

拿这个当做密码再重新登录

进去后重置密码

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

输入刚才邮箱发送的密码以及新密码保存即可

 

设置proxy代理仓库准许远程下载

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

如图将三个proxy代理仓库的Download Remote Indexes设置为true

 

Maven本地库的安装与配置

下载maven并配置环境变量,很简单,这里就不再赘述,看一下setting配置文件

下面是配置内容

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>E:\work\tools\maven\repo</localRepository>
    <interactiveMode>true</interactiveMode>
    <offline>false</offline>
    <pluginGroups>
        <pluginGroup>org.mortbay.jetty</pluginGroup>
        <pluginGroup>org.jenkins-ci.tools</pluginGroup>
    </pluginGroups>
    
    <!--配置权限,使用默认用户-->
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server> 
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>

    <mirrors>

    </mirrors>

    <profiles>
        <profile>
           <id>edu</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                    <jdk>1.8</jdk>
                </activation>
                <repositories>
                    <!-- 私有库地址-->
                    <repository>
                        <id>nexus</id>
                        <url>http://xxx.xxx.xxx.xxx:8082/nexus/content/groups/public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                    </repository>
                </repositories>      
                <pluginRepositories>
                    <!--插件库地址-->
                    <pluginRepository>
                        <id>nexus</id>
                        <url>http://xxx.xxx.xxx.xxx:8082/nexus/content/groups/public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                       </snapshots>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
    </profiles>
    
    <!--**profile-->
    <activeProfiles>
        <activeProfile>edu</activeProfile>
    </activeProfiles>
</settings>

 

注意以上标红的点
我这里使用的是开发者(deployment),nexus默认密码为deployment123

<url>http://xxx.xxx.xxx.xxx:8082/nexus/content/groups/public/</url>

这里配置的其实就是nexus中的

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

eclipse配置

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

构建jar包并上传到私有库

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

在nexus中刷新就可以看到jar包了

 

上传第三方jar包

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

选择本地jar包

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

Maven私有库与本地库的安装与配置(Sonatype nexus + Maven)

nexus刷新即可看到