maven的nexus私服搭建配置使用

1.nexus3.x安装启动

  • 以管理员身份打开cmd,进入bin目录

    • 安装服务:nexus.exe /install
    • 启动服务:nexus.exe /start
    • 停止服务:nexus.exe /stop
    • 带控制台的启动服务:nexus.exe /run
    • 卸载服务:nexus.exe /uninstall
  • 打开浏览器,访问http://localhost:8081/

  • 登录账号admin,密码见文件,第一次登录提示修改密码

2.nexus服务器预置仓库

  • 类型介绍
    • hosted:是本地仓库,用户可以把自己的一些jar包发布到hosted中,比如公司的第二方库
    • proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。不允许用户自己上传jar包,只能从中央仓库下载
    • group:仓库组,用来合并多个hosted/proxy仓库,当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可
    • virtual:虚拟仓库,基本废弃了
  • 预置仓库
    • Central:该仓库代理Maven中央仓库,其策略为Release,因此只会下载和缓存中央仓库中的发布版本构件
    • Releases:这是一个策略为Release的宿主类型仓库,用来部署正式发布版本构件
    • Snapshots:这是一个策略为Snapshot的宿主类型仓库,用来部署开发版本构件
    • 3rd party:这是一个策略为Release的宿主类型仓库,用来部署无法从maven中央仓库获得的第三方发布版本构件,比如IBM或者oracle的一些jar包(比如classes12.jar),由于受到商业版权的限制,不允许在中央仓库出现,如果想让这些包在私服上进行管理,就需要第三方的仓库
    • Public Repositories:一个组合仓库

3.将项目发布到maven私服

  • maven的setting.xml配置

    xml 复制代码
    <?xml version="1.0" encoding="UTF-8"?>
    
    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
      <!-- 本地仓库路径 -->
      <localRepository>D:\repo</localRepository>
    
      <pluginGroups>
      </pluginGroups>
    
      <proxies>
      </proxies>
    
      <servers>
        <!-- nexus私服 -->
        <server>
          <id>nexus-gen</id>
          <username>admin</username>
          <password>Gen123</password>
        </server>
      </servers>
    
      <mirrors>
        <!-- nexus镜像 -->
        <mirror>
          <id>nexus-gen</id>
          <mirrorOf>*</mirrorOf>
          <name>maven-public</name>
          <url>http://localhost:8081/repository/maven-public/</url>
        </mirror>
      </mirrors>
    
      <profiles>
        <profile>
          <id>gen</id>
          <repositories>
            <repository>
              <id>nexus-gen</id>
              <name>maven-public</name>
              <url>http://localhost:8081/repository/maven-public/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
            </repository>
          </repositories>
        </profile>
      </profiles>
    
      <activeProfiles>
        <activeProfile>gen</activeProfile>
      </activeProfiles>
    </settings>
  • 项目中pom.xml配置

    xml 复制代码
    <distributionManagement>
        <repository>
            <id>nexus-gen</id>
            <name>gen</name>
            <url>http://localhost:8081/repository/gen/</url>
        </repository>
    </distributionManagement>
  • 然后在项目中clean deploy即可

相关推荐
半个脑袋儿3 小时前
Maven版本号管理规范:为何父POM是统一依赖版本的最佳实践?
spring boot·maven
吾日三省吾码4 小时前
改善 Maven 的依赖性
java·maven
疯狂学习GIS6 小时前
本地安装JAR包出现The goal you specified requires a project to execute的处理
java·后端·maven
Webgiserin10 小时前
maven 和 idea intej步骤记录
java·maven·intellij-idea
Leaf吧10 小时前
Maven
java·maven
就是蠢啊13 小时前
Maven 基础知识
java·maven
helloworld工程师1 天前
【微服务】SpringBoot整合LangChain4j 操作AI大模型实战详解
java·eclipse·tomcat·maven
magic 2451 天前
MyBatis的缓存、逆向工程、使用PageHelper、使用PageHelper
java·spring·maven·mybatis
s_yellowfish1 天前
Maven笔记
java·笔记·maven
爱的叹息1 天前
关于 Spring Boot 后端项目使用 Maven 打包命令、JAR/WAR 对比、内嵌服务器与第三方服务器对比,以及热部署配置的详细说明
spring boot·maven·jar