本地使用nexus3.18.1 repository manager搭建maven私服及使用

1、安装nexus

1.1 进入nexus解压目录后,打开cmd, 注册nexus服务

	nexus.exe  /install nexus

1.2 启动nexus服务

nexus.exe /start nexus

现在,就可以访问localhost:8081,登录管理页面了。
1.3 登录
以前版本的nexus,默认登录账号是:admin,密码:admin123
不过我登录时,却发现密码错误
在这里插入图片描述
仔细看提示,告诉你admin账户的密码在sonatype-work\nexus3下边的admin.password文件中,根据提示路径打开这个文件即可看到一长串密码,这样就能登录了。
瞧瞧,登录后的界面和原来也不一样了,初始生成的仓库都和nexus2不太一样
在这里插入图片描述

看来nexus3之后考虑到安全性,登录密码改成随机生成的了,而且登录成功后会引导你修改admin账号的密码,安全感满屏有木有。。。

2、安装私服

安装私服前,可是看了不少文档,归根到底主要就是2件事儿:

2.1 在settign.xml(针对全局)或者具体某个pom.xml(针对具体的项目)文件中配置仓库的信息
仅以setting.xml文件中配置为例:
id: 就是每个repository的唯一标识,其实就是name
在这里插入图片描述
name:这个个性化配置吧
url:图中URL列下边有很多copy,点击就能看到。

<profiles>
  <profile>
		<id>myProfile</id>
		<repositories>
			<repository>
				<id>maven-public</id>
				<name>Repository for me</name>
			    <url>http://localhost:8081/repository/maven-public/</url>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>maven-public</id>
				<name>PluginRepository for me</name>
				<url>http://localhost:8081/repository/maven-public/</url>
			</pluginRepository>
		</pluginRepositories>
	</profile>
  </profiles>
   <!--使用profile定义仓库需要激活才可生效-->  
  <activeProfiles>  
   <activeProfile>myProfile</activeProfile>  
 </activeProfiles>  

2.2 如果需要上传jar包到私服,还要进行权限校验,这个也非常简单
2.2.1 在setting.xml中配置server
记住这个id,在这儿使用账号密码进行了校验,在pom.xml中配置上传到哪个仓库时,要用到这个id

<servers>
	<server>
      <id>snapshotRepo</id>
      <username>nexus中配置的用户名,也可以直接用admin</username>
      <password>对应账户的密码</password>
    </server>
    <server>
      <id>releaseRepo</id>
      <username>admin</username>
      <password>admin密码</password>
    </server>
    </servers>

2.2.2 在pom.xml中配置distributionManagement
看到了吧,id就是server的id,两处配置通过这个id关联起来了。
name:个性化吧
url:还是仓库中URL那一列的值,注意上传类型snapshot和release分别对应各自的仓库

<distributionManagement>
        <snapshotRepository>
            <id>snapshotRepo</id>
            <name>maven-snapshots</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
        <!--<repository>
            <id>releaseRepo</id>
            <name>maven-release</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </repository>-->
    </distributionManagement>

3、配置阿里云镜像

在setting.xml文件中增加:

<mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun  Mirror</name>
      <mirrorOf>central</mirrorOf>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>  
  </mirrors>

让maven飞起来吧!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值