搭建maven私服

1、下载nexus安装包
wget http://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.6.0-02-unix.tar.gz
或者 上官网下载 https://www.sonatype.com/download-sonatype-trial?submissionGuid=f15e6fa2-fdd0-4d15-9aae-93fd99396cde
2、解压 tar -zxvf nexus-3.6.0-02-unix.tar.gz
3、进入目录 cd nexus-3.6.0-02
启动 Nexus(默认端口是8081),Nexus 常用的一些命令包括:bin/nexus {start|stop|run|run-redirect|status|restart|force-reload},下面我们启动Nexus:
启动命令:bin/nexus start
(可以使用bin/nexus status 查看下使用启动成功,如果没有的话,可以使用bin/nexus run 看下报错信息)
4、访问nexus界面 http://ip:8081/ (记得在防火墙开放8081端口。可以参考
https://blog.csdn.net/qq_43060570/article/details/117110732)
(如果你的版本是nexus 是2.x 默认用户名和密码是 admin admin123,是3.x的话用户名时admin ,密码在你进入页面时提示你密码所在的文件位置,通常是在nexus3目录下的admin.password文件中)

5、四种仓库类型介绍
默认仓库介绍

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

2)maven-releases: 私库发行版jar

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

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

Nexus默认的仓库类型有以下四种:(上面的名字可以随便取,关键是它对应的是什么仓库类型)

1)group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;

2)hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);

3)proxy(代理类型): 从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);

4)virtual(虚拟类型): 虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);

Policy(策略):表示该仓库为发布(Release)版本仓库还是快照(Snapshot)版本仓库;

6、修改中央仓库为阿里云http://maven.aliyun.com/nexus/content/groups/public/
在这里插入图片描述
在这里插入图片描述
还有修改 maven-releases 的Deployment policy的配置在这里插入图片描述7、上传本地需要使用的jar上nexus在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这样就完成了

8、maven setting配置
可以分两种 使用mirror的
需要注释之前配置的阿里云仓库,因为mirror配置是只生效第一个,在第一个mirror中断后,才会链接第二个mirror
注意:是引用maven-public,是group类型,因为他包含了你存放本地jar包的库和代理阿里云的仓库,如果你有新增的Repositories(仓库)也是放在里面

	<mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus teamwings</name>
        <url>http://xxxxxx:8081/repository/maven-public/</url>
    </mirror>

在这里插入图片描述
第二种,配置多个远程仓库(需要注释掉mirrors节点)

<profiles>
	<profile>
        <id>companyRepository</id>
        <repositories>
            <repository>
                <id>teamwings</id>
                <!--你需要依赖的库,不一定要group了,因为下面配置了阿里云的仓库,这里就不需要在引用代理仓库了,引用你存放本地jar的库就可以了-->
                <url>http://xxxxxxx:8081/repository/maven-releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile>
    <profile>
        <id>aliyunRepository</id>
        <repositories>
            <repository>            
                <id>aliyun</id>             
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile>
  </profiles>

    <activeProfiles>
    <activeProfile>companyRepository</activeProfile>
    <activeProfile>aliyunRepository</activeProfile>
  </activeProfiles>

这样就大功告成了,可以在你的项目中引用第三方jar包了

		<dependency>
            <groupId>sun.tools</groupId>
            <artifactId>tools</artifactId>
            <version>1</version>
        </dependency>

如果你需要把项目install上私服的话,maven需要添加一下配置

	<servers>  
        <server> 
        	<!--下面仓库的id--> 
            <id>nexus</id>  
            <username>admin</username>  
            <password>admin123</password>  
        </server>  
    </servers>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值