nexus 3 搭建私服maven仓库

时间:2022-05-18 04:02:19

下载sonatype nexus repository manager 3.x oss版
下载地址:http://www.sonatype.com/download-oss-sonatype

安装
windows版
进入bin目录下执行: nexus.exe/install     此步骤会安装nexus服务,可以到系统服务(cmd → services.msc)中查看nexus服务是否存在

nexus 3 搭建私服maven仓库

遇到上述问题,拿管理员权限打开cmd,再次执行

nexus 3 搭建私服maven仓库

nexus 3 搭建私服maven仓库

再执行nexus.exe/run启动

linux版
解压缩tar xvzf nexus-3.14.0-04-unix.tar.gz
进入bin目录  执行./nexus run

nexus 3 搭建私服maven仓库

出现上图说明启动成功

启动后登录地址:http://localhost:8081
默认admin/admin123

修改端口号

默认8081端口号,如果想换一个端口号修改配置文件,经查找配置文件在    /home/tqhy/java/nexus-3.14.0-04/etc/nexus-default.properties,修改端口为8082,重启即可。

nexus 3 搭建私服maven仓库

停止nexus服务

stop命令虽然报了nexus停止的信息,但是nexus并没有停止

tqhy@tqhy-P5K-E:~/java/nexus-3.14.0-04/bin$ ./nexus stop
Shutting down nexus
nexus is not running.

发现直接在启动服务的终端执行ctrl+c,服务就停了,如果终端关闭,杀死nexus进程

让所有的maven项目使用私库
配置maven的settings.xml

  <servers>
    <server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>maven-public</id>
      <name>maven-public</name>
      <url>http://localhost:8081/repository/maven-public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
        <id>nexus</id>
      <repositories>
        <repository>
          <id>maven-central</id>
          <url>http://localhost:8081/repository/maven-central/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>maven-central</id>
          <url>http://localhost:8081/repository/maven-central/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

单个项目使用私库
配置maven的settings.xml

  <servers>
    <server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors>
      <mirror>
      <id>maven-public</id>
      <name>maven-public</name>
      <url>http://localhost:8081/repository/maven-public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

配置项目的pom.xml

  <distributionManagement>
      <snapshotRepository>
        <id>maven-snapshots</id>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
      </snapshotRepository>
      <repository>
        <id>maven-releases</id>
        <url>http://localhost:8081/repository/maven-releases/</url>
      </repository>
  </distributionManagement>

  <repositories>
       <repository>
         <id>maven-public</id>
         <url>http://localhost:8081/repository/maven-public/</url>
       </repository>
  </repositories>

将工程导为jar包上传到私库
对工程执行deploy -e命令

nexus 3 搭建私服maven仓库

遇到问题

1、low disk watermark...replicas will not be assigned to this node

nexus 3 搭建私服maven仓库

网上说要清理磁盘空间

我当时在下载,占用很大内存,后来删掉了,这个问题就没了

2、Failed to transfer http://xx.xx. Error code 400, Repository version policy: RELEASE does not allow metadata in path: cn/blueboz/train/hibernate/0.0.1-SNAPSHOT/maven-metadata.xml -> [Help 1]

deploy 出现问题,是因为将部署路径写错,错误在于建立的仓库是RELEASE版本,上传的jar包是SNAPSHOT版本,改成RELEASE版本就好了

参考:
https://blog.csdn.net/liumiaocn/article/details/61931847
https://blog.csdn.net/cuncaojin/article/details/81270897
https://help.sonatype.com/repomanager3/installation/installation-methods

https://blog.csdn.net/blueboz/article/details/63686679
https://www.cnblogs.com/hanhuibing/articles/5530820.html

nexus 3 搭建私服maven仓库