nexus下载及上传jar包

本文详细介绍了如何在Linux上搭建Nexus私服,包括配置Maven的settings.xml,使用Nexus下载和上传jar包,以及发布项目到Maven私服的步骤。通过Nexus,可以便捷地管理依赖并实现中央仓库的缓存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先在linux搭建nexus

linux搭建nexus

获取nexus地址

在maven的settings.xml中配置私服地址

打开maven的settings.xml文件

1 在 servers 标签 中添加 配置私服用户名密码

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
	
	<!--配置私服用户名密码-->
	<server>
		<id>releases</id>
		<username>admin</username>   
		<password>admin123</password>
		</server>
		<server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	<!--配置私服用户名密码结束-->

  </servers>

2 在 profiles 标签 中添加 配置私服下载jar包的模板

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
	
	<!--配置私服下载jar包的模板 开始-->
	<profile>
	<id>dev</id>
		<repositories>
		<repository>
			<id>nexus</id>
		<!--仓库地址,即nexus仓库组的地址
		http://localhost:8081/nexus/content/groups/public/
		-->
			<url>
			http://ip:8081/repository/maven-public/
			</url>
		<!--是否下载releases构件-->
			<releases>
			<enabled>true</enabled>
			</releases>
		<!--是否下载snapshots构件-->
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
		</repositories>
		<pluginRepositories>
			<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件
			http://localhost:8081/nexus/content/groups/public/			
			-->
			<pluginRepository>
				<id>public</id>
				<name>Public Repositories</name>
				<url>
				http:/ip:8081/repository/maven-public/
				</url>
				</pluginRepository>
				</pluginRepositories>
		</profile>
		
	<!--配置私服下载jar包的模板 结束-->

	
  </profiles>

3 在 settings 末尾添加 激活模板

<!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
  
  <!--激活模板 开始-->
  <activeProfiles>
	<activeProfile>dev</activeProfile>
  </activeProfiles>
   <!--激活模板 结束-->

</settings>

使用nexus私服下载jar包

即pom.xml中导入jar包坐标,若本地仓库没有,会通过nexus下载;若nexus没有,nexus会向中央仓库下载,nexus配置的仓库中会存放下载的jar包。
在这里插入图片描述

本地仓库没有,nexus下载的jar包
在这里插入图片描述

将jar包上传nexus私服

将第三方jar安装到本地仓库
①下载Oracle的jar包(略)

②在cmd中使用mvn install命令进行安装

mvn install:install-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 – Dversion=10.2.0.4.0 -Dpackaging=jar

将第三方jar安装到maven私服

①下载Oracle的jar包(略)

②在cmd中执行mvn deploy命令进行安装


​      mvn deploy:deploy-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 –

​      Dversion=10.2.0.4.0 -Dpackaging=jar –

​      Durl=http://ip:8081/repository/nuget-hosted/ -DrepositoryId=thirdparty

http://ip:8081/repository/nuget-hosted/ -->即上传jar的仓库地址

将项目发布到maven私服

1 配置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>

2 配置项目的pom.xml文件

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

3 执行mvn deploy命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岿然如故

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值