cmd查看maven版本_新手如何构建Maven私服

db9c5750d6cc8a12e2058fa6611c0633.png

maven私服使用场景

在实际开发中,项目中可能会用到第三方的jar、或者公司内部人员写好的公共jar包

1. 缓存公司内部使用的jar包

linux系统:

基于docker安装maven私服

步骤:

1.下载一个nexus3的镜像:

docker pull sonatype/nexus3

2.将容器内部/var/nexus-data 挂载到主机:

docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3

记得关闭防火墙, service iptables stop 关闭防火墙

访问http://ip:8081

Maven默认账号密码

b236055ac319e08a0015f40db734c1b6.png

进入到容器中 :

docker run -d -p 8081:8081 --name nexus -v /root/nexus-data:/var/nexus-data --restart=always sonatype/nexus3

cat /nexus-data/admin.password

912c3b4fc8b5077438f3d2b25208a9d2.png

复制该密码 账号为admin

80265841eddfa9cdefb8ee859371e05b.png

修改最新的密码为你自己的密码

​访问地址:http://ip:8081/

登录

Windows系统

1.首先下载一个Nexus:官网

官方说明文档:https://help.sonatype.com/repomanager3/installation/run-as-a-service#RunasaService-Windows

Nexus 简介:

Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问。利用Nexus你可以只在一个地方就能够完全控制访问 和部署在你所维护仓库中的每个Artifact。Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据

如下图:

7fce311e56eba8e609ca767cbb218d19.png

选择windows版本

2.安装Nexus

a.解压Nexus

8082a2410eb1ee3020769141a2595bad.png

b.进入nexus目录:

e0db1ff68ea49543efaf02134a81fe71.png

c.从cmd中进入到当前目录输执行命令 nexus.exe /install nexus:

9ff2c94d39511584df85733ba97781a1.png

执行命令-启动:nexus.exe /start

访问地址:http://ip:8081/

默认用户名/密码: admin admin123

使用:

创建一个SpringBoot项目发布

创建仓库,点击Create repository,然后选择maven2(hosted)然后输入仓库名称(test-release)。在version policy中选择这个仓库的类型,这里选择release,在Deployment policy中选择Allow redeploy(这个很重要).

创建私服账号

点击左侧菜单栏的Users菜单,然后点击Create local user.我这里创建了一个用户,账号密码比如:admin、admin123

本地maven配置

修改本地maven的settings文件   

在servers下增加server:

<server>
<id>test</id>
<username>admin</username>
<password>admin123</password>
</server>

在mirros下增加mirror:

<mirror>
<id>test</id>
<mirrorOf>*</mirrorOf>
<url>http://ip:8081/repository/maven-public/</url>
</mirror>

注意: server和mirror的id要一致

SpringBoot项目核心配置

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.coolhy</groupId> <artifactId>coolhy-springboot</artifactId> <version>1.0-release</version> <!--注意限定版本一定为RELEASE,因为上传的对应仓库的存储类型为RELEASE --> <!--指定仓库地址 --> <distributionManagement> <repository> <!--此名称要和.m2/settings.xml中设置的ID一致 --> <id>test</id> <url>http://ip:8081/repository/coolhy-release/</url> </repository> </distributionManagement> <build> <plugins> <!--发布代码Jar插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> </plugin> <!--发布源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build></project>

Maven 执行命令 mvn deploy 上传jar包即可

注意版本号码一定要是为:release版本 ,否则上传jar报错

本地项目引入maven私服jar

<dependencies>
<dependency> <groupId>com.coolhy</groupId> <artifactId>coolhy_springboot</artifactId> <version>0.0.1-RELEASE</version> </dependency> </dependencies> <repositories> <repository> <id>test</id> <url>http://ip:8081/repository/coolhy-release/</url> </repository> </repositories>

至此,项目中就可以从私服中拉取jar包了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值