说明

  1. 部署自定义jar包就是将我们自己编写好的程序打成jar包,然后上传到nexus上供其他人下载

    账号类型

  2. 默认nexus有三种账号,如下 | 账号 | 作用 | | :—-: | :—-: | | admin | 超级用户 | | deployment | 可以进行部署和搜索等操作,但是在nexus3.x中已经取消了 | | anonymous | 如果没有任何认证信息,那么就是anonymous这个匿名帐号了,可以下载和查看依赖 |

设置deployment账号

  1. 进入nexus -> 登录admin用户 -> Security -> Roles -> Create Role -> Nexus role,填写如下内容,最后点击Create Role

image.png

  1. 创建用户,进入nexus -> 登录admin用户 -> Security -> Users -> Create local user,填写如下内容,并将前面创建好的role授权给他

image.png

部署专用账号配置

  1. 在maven setting的server标签中填写deployment的账号和密码 ```xml nexus-releases deployment deployment123 nexus-snapshots deployment deployment123
  1. ![image.png](https://cdn.nlark.com/yuque/0/2020/png/2463114/1607295861152-122566bf-a84c-4080-9433-f05c8625496f.png#align=left&display=inline&height=340&margin=%5Bobject%20Object%5D&name=image.png&originHeight=340&originWidth=1215&size=30776&status=done&style=none&width=1215)
  2. <a name="3GhtS"></a>
  3. ## 发布仓库配置
  4. 1. 将项目发布包部署到哪个仓库中,是需要用项目的pom.xml中的配置来设置的,添加仓库信息,仓库地址信息可以在maven私服中获取,每个仓库后面有个copy,这里面就是地址信息
  5. ```xml
  6. <distributionManagement>
  7. <repository>
  8. <id>nexus-releases</id>
  9. <name>Nexus Release Repository</name>
  10. <url>http://localhost:8081/repository/maven-releases/</url>
  11. </repository>
  12. <snapshotRepository>
  13. <id>nexus-snapshots</id>
  14. <name>Nexus Snapshot Repository</name>
  15. <url>http://localhost:8081/repository/maven-snapshots/</url>
  16. </snapshotRepository>
  17. </distributionManagement>

image.png

执行Maven deploy命令部署到私服

  1. 在idea中指定deployment命令,将jar包部署至私服中

image.png

  1. 出现BUILD SUCCESS后就可以去maven私服检查是否有上传成功

image.png

手动上传

  1. 对于一些中央仓库没有的第三方的jar包就需要我们手动进行上传了,约定俗成上传至nexus-3rd-party这个仓库中


  1. 在maven setting中配置nexus-3rd-party的server信息

    <server>
     <id>nexus-3rd-party</id>
     <username>deployment</username>
     <password>deployment123</password>
    </server>
    

    image.png

  2. 使用命令行的方式进行上传

    mvn deploy:deploy-file -DgroupId=com.csource -DartifactId=fastdfs-client-java -Dversion=1.24 -Dpackaging=jar -Dfile=F:\DevelopmentKit\fastdfs_client_v1.24.jar -Durl=http://localhost:8081/repository/3rd-party/ -DrepositoryId=nexus-3rd-party
    

    image.png

  3. 进入maven私服进行验证

image.png