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

一、搭建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 设置

      my-deploy-release
      admin
      admin123
    

    
      my-deploy-snapshot
      admin
      admin123
    



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


    
        my-deploy-release
        http://192.168.1.123:8081/nexus/content/repositories/releases/
    

    
        my-deploy-snapshot
        http://192.168.1.123:8081/nexus/content/repositories/snapshots/
    



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



    
        
            localRepository
            file:D:/Workspace/Repository
        
    

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

你可能感兴趣的:(Linux)