Maven学习总结(5)Nexus私服的搭建和使用

本文介绍了Maven私服的优点及Nexus私服的具体安装步骤,并详细展示了如何配置maven以使用私服,包括设置用户名密码、镜像路径等。

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

对于使用maven来说,私服的好处是显而易见的。

首先,使用私服会提高jar包加载的速度,当本地jar包没有时他会查找私服,私服没有才会查找远程中央仓库,而私服一般是在局域网内的。

其次,使用私服的安全性比较高,只有私服连接外网的情况下,被攻击目标就只剩下私服,安全的关注点也就少了。

同时,私服的jar包可以存在公司项目特有的,同事之间可以通过maven共享,而不需要拷贝,十分方便。

Nexus私服的安装:

链接:https://pan.baidu.com/s/1mbm9mvtmDnd41yYCckGOng 密码:2rfb

下载 nexus-2.5-bundle.zip 并解压, 进入如图所示目录,找到对应版本的系统文件夹打开

我这里在window系统安装

安装完成后可以在服务中看到,启动它

 输入服务器地址和端口,端口默认是默认是8081 http://localhost:8081/nexus,出现如下界面启动成功。

 

 端口号可以在如下目录修改:

 

然后在你的maven配合文件中配置一下,连接私服。如图:

配置访问私服的用户名密码以及访问私服的镜像路径。如图。 

 

 配置属性文件,以及激活属性 如图:

 配置完成的setting.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  
  <localRepository>D:\maven\apache-maven-3.5.4-bin\apache-maven-3.5.4\repository</localRepository>
  
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>
  <mirrors>
	<mirror>    
      <id>nexus</id>  
      <name>nexus</name>
	  <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>     
    </mirror>
  </mirrors>
  <profiles>
   <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2/</url>    
          <releases><enabled>true</enabled></releases>
		  <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
	  <pluginRepositories>
		<pluginRepository>
			<id>central</id>
			<url>http://repo1.maven.org/maven2/</url>   
			<releases><enabled>true</enabled></releases>
			<snapshots><enabled>true</enabled></snapshots>
		</pluginRepository>
	  </pluginRepositories>
    </profile>
  </profiles>
 <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

 这样,私服就可以正常使用了。

配置过程中的路径 mirriors中的路径为私服中获取的组仓库路径:如图:

nexus默认管理员登录账号密码为admin/admin123

如何上传jar包到第三方仓库:

 

 

 

 上传成功后可以通过这样获取依赖的坐标,直接使用。

 shang

 下载私服中的jar包,直接通过配置pom.xml 文件依赖,指定需要下载依赖的坐标,ide会自动加载,你也可以重建项目。

最后,是配置将自己的项目打包部署到私服的的配置代码,需要在pom.xml 中配置

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

 url还是通过访问私服获取

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值