开发中,若不能连接互联网,且使用到了Maven开发,那是很郁闷的。但是先将开发中要用的jar缓存到本地仓库,在借助本地仓库拷贝,进行开发。若涉及到团队开发,还是希望共用一个Maven库,这时候可以借助Nexus构建私有服务器。
1.下载Nexus:地址Download Archived Nexus Releases,可以选择喜欢的版本,下载完毕后,由于我是在Linux,我选择了Download Nexus 2.12.0-01(TGZ)
2.解压Nexus到指定文件夹
sudo mkdir /nexus
sudo tar -zxvf nexus-2.12.0-01-bundle.tar.gz -C /nexus
Nexus不推荐使用root启动服务,所以将文件夹所有者改为普通用户
sudo chown user1:user1 nexus -R
3.启动Nexus服务
cd /nexus/nexus-2.12.0-01/bin
./nexus start
4.登陆http://192.168.186.137:8081/nexus访问登陆名admin/admin123(初始账号)
点击Repositories->Central->Configuration中的Download Remote Indexes设置为true,并保存。
5.修改Maven配置文件,在Maven插件的settting.xml配置文件中 <setting>中添加如下代码
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-linux-nexus</id>
<url>http://192.168.186.137:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- activeProfiles | List of profiles that are active for all builds. | -->
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
这里基本上就完成了。但是若是在完全不能连接互联网环境下,可以将本地仓库导入到仓库服务器上,
然后将所有的文件移动到中央仓库。
在拷贝本地仓库之前
现在整个本地仓库考本到Linux服务器上,如拷贝到桌面上
移动所有的相关文件
cd /home/docker/Desktop/m2/repository
mv * /nexus/sonatype-work/nexus/storage/public/
查看此时导入情况
先关参考