centos7 搭建nexus 仓库配置和maven发布jar包到仓库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013719012/article/details/82896191

一、搭建nexus 仓库

## 创建/usr/local/nexus 目录
$ mkdir /usr/local/nexus ; /cd /usr/local/nexus

## 下载nexus 安装包
$ wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.13.0-01-unix.tar.gz

##解压 安装包
$  tar -zxvf apache-maven-3.5.4-bin.tar.gz

## 启动、时间会比较长
$ cd /usr/local/nexus/nexus-3.13.0-01/bin ; ./nexus run &

-------------出现这个代表成功--------------
Started Sonatype Nexus OSS 3.13.0-01
-----------------------------------------

## 修改防火墙开启服务器访问端口
$ firewall-cmd --zone=public --add-port=8081/tcp --permanent
$ firewall-cmd --reload

## 设置开机自启
$ vim /usr/lib/systemd/system/nexus.service

## 写入以下内容
[Unit]
Description=nexus service

[Service]
Type=forking
LimitNOFILE=65536 #警告处理
ExecStart=/usr/local/nexus/nexus-3.13.0-01/bin/nexus start
ExecReload=/usr/local/nexus/nexus-3.13.0-01/bin/nexus restart
ExecStop=/usr/local/nexus/nexus-3.13.0-01/bin/nexus stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

## 设置开机启动
$ systemctl enable nexus.service
$ systemctl daemon-reload

##修改nexus 的运行用户为root
$ vim nexus.rc
run_as_user="root"

## 打开浏览器访问 http://你的IP:8081/nexus
用户名:admin
密码:admin123

二、配置maven发布jar包

## maven 的settings.xml 设置
<server>
      <id>my-deploy-release</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

    <server>
      <id>my-deploy-snapshot</id>
      <username>admin</username>
      <password>admin123</password>
    </server>



## 在项目的pom.xml中 设置

<distributionManagement>
    <repository>
        <id>my-deploy-release</id>
        <url>http://192.168.1.123:8081/nexus/content/repositories/releases/</url>
    </repository>

    <snapshotRepository>
        <id>my-deploy-snapshot</id>
        <url>http://192.168.1.123:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>


####
使用maven可以方便的开发好的jar包发布到本地仓库中,方便其他项目依赖使用,在pom.xml文件中添加如下的配置:



    <distributionManagement>
        <repository>
            <id>localRepository</id>
            <url>file:D:/Workspace/Repository</url>
        </repository>
    </distributionManagement>

然后再命令行中输入 * mvn deploy * 即可发布url所指定的本地目录中。

猜你喜欢

转载自blog.csdn.net/u013719012/article/details/82896191