maven私服的搭建以及如何将项目上传到私服

maven私服的搭建以及如何将项目上传到私服
声明:这里是Nexus搭建的Maven私服
下载地址:http://www.sonatype.org/nexus/archived/

  • 第一步:安装Nexus和解释

    将nexus压缩包加压
    这是解压后的样子
    在这里插入图片描述

在这里插入图片描述

  • 使用指令 nexus install 安装

在这里插入图片描述

  • 找到nexus服务并启动
    在这里插入图片描述
  • 查看nexus的配置文件conf/nexus.properties
# Jetty section
application-port=8081  	# nexus的访问端口配置
application-host=0.0.0.0 	# nexus主机监听配置(不用修改)
nexus-webapp=${bundleBasedir}/nexus 	# nexus工程目录
nexus-webapp-context-path=/nexus	 # nexus的web访问路径
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus   # nexus仓库目录
runtime=${bundleBasedir}/nexus/WEB-INF  # nexus运行程序目录
  • 访问:
    http://localhost:8081/nexus/
    在这里插入图片描述
    点击右上角的Log in,输入账号和密码 登陆
    使用Nexus 内置 账户:admin 密码:admin123 登陆
  • 仓库类型解释
  • hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库
  • proxy,代理仓库,用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件。
  • group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组。
  • virtual(虚拟):兼容Maven1 版本的jar或者插件
    在这里插入图片描述
  • 第二步:从私服下载jar的过程
  • 将仓库索引加入你的仓库
    加入的路径:sonatype-work\nexus\indexer\central-ctx
    注意:在加入索引时先关闭Nexus服务
    在这里插入图片描述
    加入后的搜索结果
    在这里插入图片描述
    在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库。
<profile>   
	<!--profile的id-->
   <id>dev</id>   
    <repositories>   
      <repository>  
		<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
        <id>nexus</id>   
		<!--仓库地址,即nexus仓库组的地址-->
        <url>http://localhost:8081/nexus/content/groups/public/</url>   
		<!--是否下载releases构件-->
        <releases>   
          <enabled>true</enabled>   
        </releases>   
		<!--是否下载snapshots构件-->
        <snapshots>   
          <enabled>true</enabled>   
        </snapshots>   
      </repository>   
    </repositories>  
	 <pluginRepositories>  
    	<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
        <pluginRepository>  
        	<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
            <id>public</id>  
            <name>Public Repositories</name>  
            <url>http://localhost:8081/nexus/content/groups/public/</url>  
        </pluginRepository>  
    </pluginRepositories>  
  </profile>
  • 激活仓库的配置
<activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
  • 在pom.xml的配置文件的配置,让jar从私服下载
<repositories>
    <repository>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>public</id>
      <name>Public Repositories</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>public</id>
      <name>Public Repositories</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </pluginRepository>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>

第三步:将项目上传到私服的过程

需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 。此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。

 <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

配置项目的pom.xml文件

<distributionManagement>
  	<repository>
  		<id>releases</id>
	<url>http://localhost:8081/nexus/content/repositories/releases/</url>
  	</repository> 
  	<snapshotRepository>
  		<id>snapshots</id>
	<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  	</snapshotRepository> 
  </distributionManagement>

测试:先启动Nexus服务在使用deploy命令将项目发布到私服
根据自己的项目的版本,上传到不同的宿主仓库
snapshots
releases
在这里插入图片描述
在这里插入图片描述

  • 可以使用下面的配置引用自己的项目

在这里插入图片描述

  • 补充:可以管理仓库组

在这里插入图片描述

转载来源:https://blog.csdn.net/weixin_44388207/article/details/86311021

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值