nexus3安装和使用

一、nexus3的安装和启动

1.在官网下载nexus3

2.安装nexus

解压到指定文件夹D:\nexus3\,得到 nexus-3.16.2-01 文件夹和 sonatype-work 文件夹,nexus-3.16.2-01文件夹放的是nexus服务器相关的文件,sonatype-work放的是nexus工作的数据文件,上传下载的jar包就在这个文件夹下面。

在命令提示符中进去D:\nexus3\nexus-3.16.2-01\bin文件夹,执行命令:nexus /run,访问http://localhost:8081。

二、nexus3的使用

1.登录nexus

使用默认用户admin,密码admin123,登录。

2.管理本地仓库

Nexus有3个类型的数据仓库,分别是hosted,proxy,group。

hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件以及自己或第三方的项目构件;
proxy 代理仓库:代理公共的远程仓库;
group 仓库组:Nexus 通过仓库组统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。

Nexus预定义了2个本地仓库,分别是maven-releases, maven-snapshots。

maven-releases:这里存放我们自己项目中发布的构建, 通常是Release版本的。
maven-snapshots:这个仓库非常的有用, 它的目的是让我们可以发布那些非release版本, 非稳定版本。

我们还可以自己创建仓库

如果是创建的proxy仓库或者hosted仓库,需要添加到公共仓库里。

3.上传本地jar包

4.在maven中配置私服,编辑setting.xml

<servers>
    <server>
    <!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 -->
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
     </server>
</servers>

<!--为仓库列表配置的下载镜像列表。  -->
<mirrors>
    <mirror>
        <!--该镜像的唯一标识符。id用来区分不同的mirror元素。  -->
        <id>nexus</id>
        <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
        <mirrorOf>*</mirrorOf>
        <name>central repository</name>
        <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。  -->
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
    </mirror>
</mirrors>

<profiles>
  <profile>
      <id>nexus</id>
      <!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。  -->
      <repositories>
          <!--发布版本仓库-->
          <repository>
              <id>nexus</id>      
              <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
              <url>http://127.0.0.1:8081/repository/maven-public/</url>
          <!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
              <enabled>true</enabled>
          </snapshots>
      </repository>
      </repositories>
  </profile>     
</profiles>

<!--激活配置-->
<activeProfiles>
    <!--profile下的id-->
    <activeProfile>nexus</activeProfile>
</activeProfiles>

通过命令行上传jar到nexus:

mvn deploy:deploy-file -DgroupId=com.sgcc.ams -DartifactId=ams-base -Dversion=1.7.0 -Dpackaging=jar -Dfile=C:\develop\lib\ams-base-1.7.0.jar -Durl=http://127.0.0.1:8081/repository/maven-releases/ -DrepositoryId=nexus

在项目中配置私服,pom.xml中添加

<!--上传到nexus仓库中,配合mvn deploy:deploy-->
<distributionManagement>
    <repository>
        <id>nexus</id>
        <name>Nexus snapshots Repository</name>
        <!--snapshots仓库 -->
        <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
    </repository>
</distributionManagement>

通过命令行执行mvn deploy即可。

 内容部分参考:

https://blog.csdn.net/cool_summer_moon/article/details/78779530
https://blog.csdn.net/u013887008/article/details/79429973

 

posted @ 2019-06-19 17:29  breeze.zZ  阅读(9843)  评论(0编辑  收藏  举报