1.1 私服部署结构
在公司的局域网内部署一台服务器,服务器上安装maven私服软件。
服务器上存储了maven仓库。
在私服环境下本地项目找jar流程是:
1、先找本地仓库
2、如果本地仓库没有从私服找
3、如果私服没有从中央仓库下载,下载成功将jar向私服和本地仓库都存一份。
1.2 安装私服
下载Nexus, 下载地址:http://www.sonatype.org/nexus/archived/
下载:nexus-2.12.0-01-bundle.zip
解压nexus-2.12.0-01-bundle.zip,本教程将它解压在F盘,进入bin目录:
cmd进入bin目录,执行nexus.bat install
1.3 卸载nexus
cmd进入nexus的bin目录,执行:nexus.bat uninstall
1.4 运行nexus
方法1:
cmd进入bin目录,执行nexus.bat start
方法2:
直接启动nexus服务
查看nexus的配置文件conf/nexus.properties
默认用户名和密码 :
admin/admin123
1.5 仓库类型
1、hosted:宿主仓库,自己项目的jar要放到hosted类型的仓库中。
2、proxy:代理仓库,代理中央仓库
3、virtual:虚拟仓库,存储了maven1的构件,一般不用。
4、group:仓库组,将一些仓库组成一个组,自己项目连接仓库组去下载jar包。
平常开发中都去连接仓库组,仓库组中包括:hosted、proxy等。。
1.6 使用nexus
1.6.1 在nexus搜索jar包
在nexus加入jar包索引。
方法1:
连网下载
方法2:
手动下载索引
从网上下载:indexer-cli-5.1.0.jar
将这三者放在一个文件夹,cmd执行:
java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz -d indexer
生成索引目录:
1.6.2 将项目发布到私服(掌握)
1、在自己电脑的maven的setting.xml中配置
<server>
releases对应nexus的仓库名称
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
snapshots对应nexus的仓库名称
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
2、配置项目pom.xml
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
注意:pom.xml这里<id> 和 settings.xml 配置 <id> 对应!
3、准备将自己工程的jar发布到nexus私服中。
当你的工程版本是releases会发布到私服的releases仓库
当你的工程版本是snapshots会发布到私服的snapshots仓库
执行deploy
1.6.3 从私服下载jar包
1.6.3.1 配置仓库组:
仓库组地址:
http://localhost:8081/nexus/content/groups/public/
1.6.3.2 配置镜像
镜像地址为nexus仓库组的地址
在setting.xml配置镜像
<mirror>
<!--镜像id,mirrors中可以配置多个镜像,保证id不重复-->
<id>nexus</id>
<!--mirrorOf指定仓库id,仓库组包括了id为 releases、snapshots、thirdparty 、central 的仓库,可以配置具体的id,如果镜像所有的仓库则设置为*-->
<mirrorOf>*</mirrorOf>
<!--镜像地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
本地项目不连中央仓库,连接镜像(相当于连接私服)
浙公网安备 33010602011771号