使用Nexus3.28搭建Mevan私服,实现上传和下载jar包


前言

随着我们在开发中所需构件越来越多,需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载和浪费了外网带宽。很多情况下项目的开发都是在内网进行的,连接不到maven仓库怎么办呢?开发的公共构件怎么让其它项目使用?这个时候我们不得不为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建的进程。


一、Nexus是什么?

  • nexus是一个强大的maven仓库管理器,它极大的简化了本地内部仓库的维护和外部仓库的访问。

  • nexus是一套开箱即用的系统不需要数据库,它使用文件系统加Lucene来组织数据。

  • nexus使用ExtJS来开发界面,利用Restlet来提供完整的REST APIs,通过IDEA和Eclipse集成使用。

  • nexus支持webDAV与LDAP安全身份认证。

  • nexus提供了强大的仓库管理功能,构件搜索功能,它基于REST,友好的UI是一个extjs的REST客户端,占用较少的内存,基于简单文件系统而非数据库。

二、使用步骤

1.下载Nexus:

  1. 下载地址:https://www.sonatype.com/download-oss-sonatype

  2. 下载解压后在这个文件夹下输入cmd启动nexus
    在这里插入图片描述

    出现这个说明启动完了

  3. 在浏览器输入127.0.0.1:8081 就可以访问了,登陆后是这样,点击Sign in 进行登陆 默认账号:admin 密码:admin123
    在这里插入图片描述

2.配置参数

在这里插入图片描述

Maven用到的Repositories说明:

  • maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

  • maven-releases:私库发行版jar

  • maven-snapshots:私库快照(调试版本)jar

  • maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

  • aliyun:是我自己创建的仓库,url的地址写的是阿里云镜像的地址:

    http://maven.aliyun.com/nexus/content/groups/public/

  1. 下面这些是在maven的settig.xml中的配置,
	<servers>
		<server>  
			<id>Nexus Mirror</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server>
		<server>  
			<id>maven-public</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server>  
		<server>  
			<id>maven-releases</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server>  
		<server>  
			<id>maven-snapshots</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server>
	</servers>
<mirrors>
	<mirror>
		<id>Nexus Mirror</id>
		<name>Nexus Mirror</name>
		<url>http://127.0.0.1:8081/repository/maven-public/</url>
		<mirrorOf>*</mirrorOf>
	</mirror>
  </mirrors>
<profiles>	
<profile>  
		<id>nexus</id>  
		<repositories>
		 <!--包含需要连接到远程仓库的信息 -->
			<repository>  
			<!--远程仓库唯一标识 -->
				<id>maven-public</id> 
				<!--远程仓库URL,按protocol://hostname/path形式 --> 
				<url>http://localhost:8081/repository/maven-public/</url>  
				<releases><enabled>true</enabled></releases>  
				<snapshots><enabled>true</enabled></snapshots>  
			</repository>   
			<repository>  
				<id>maven-releases</id>  
				<url>http://localhost:8081/repository/maven-releases/</url>  
				<releases><enabled>true</enabled></releases>  
				<snapshots><enabled>true</enabled></snapshots>  
			</repository>  
			<repository>  
				<id>maven-snapshots</id>  
				<url>http://localhost:8081/repository/maven-snapshots/</url>  
				<releases><enabled>true</enabled></releases>  
				<snapshots><enabled>true</enabled></snapshots>  
			</repository> 
		</repositories> 
		<pluginRepositories>		
            <pluginRepository>  
            <!--远程仓库唯一标识 -->
				<id>maven-public</id>  
				<!--远程仓库URL,按protocol://hostname/path形式 --> 
                <url>http://localhost:8081/repository/maven-public/</url>  
                <releases><enabled>true</enabled></releases>  
                <snapshots><enabled>true</enabled></snapshots>  
            </pluginRepository>  
            <pluginRepository>  
                <id>maven-releases</id>  
                <url>http://localhost:8081/repository/maven-releases/</url>  
                <releases><enabled>true</enabled></releases>  
                <snapshots><enabled>true</enabled></snapshots>  
            </pluginRepository>    
            <pluginRepository>  
                <id>maven-snapshots</id>  
                <url>http://localhost:8081/repository/maven-snapshots/</url>  
                <releases><enabled>true</enabled></releases>  
                <snapshots><enabled>true</enabled></snapshots>  
            </pluginRepository>  
        </pluginRepositories>  
    </profile>  
</profiles>	
<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>
  1. 下面是pom.xml文件的配置
<distributionManagement>
        <repository>
        <!--这个id要和setting.xml文件里配置的一样 -->
            <id>maven-releases</id>
            <name>release</name>
            <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>

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

3.上传到Nexus私服

  1. 点击maven中的deploy就上传到私服就行了在这里插入图片描述
  2. 在私服上就可以看到了,所下jar都从私服展示了在这里插入图片描述

总结

它是一个强大的仓库管理器,极大地简化了内部仓库的维护和外部仓库的访问。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值