当前位置: 移动技术网 > IT编程>开发语言>Java > Nexus私服搭建

Nexus私服搭建

2018年11月26日  | 移动技术网IT编程  | 我要评论

 

公司之前的代码没有使用maven管理jar包,现在要求使用maven,在整理依赖的过程中发现某些jar包maven上并不更新了,还有些jar包maven上根本没有,比如钉钉的jar包。

所以没办法只能自己搭建私服,因为是在整理中,所以就在自己的windows电脑上搭建的。

nexus的官网 https://www.sonatype.com/download-oss-sonatype  我下载的是nexus-2.14.10-01-bundle版本的。

下载解压

进入nexus-2.14.10-01-bundle\nexus-2.14.10-01\bin目录,打开该目录的命令行窗口,执行nexus install 命令,安装nexus,安装完成后进入服务配置界面,启动nexus服务

windows+r 输入下面命令进入服务配置界面

服务启动成功后打开浏览器输入http://www.lhsxpumps.com/_localhost:8081/nexus nexus默认端口是8081

点击右上角的log in 登录,默认账号: admin  默认密码 :admin123

 

登录成功后点击左边的views/repositories下的repositories 打开repositories窗口可以看到默认创建的一些仓库,我这里使用到了public repositories 和 3rd party  public repositories是公共的仓库,maven仓库下载的会放在这里,3rd party是第三方仓库,我们可以自己添加网上下载下来的第三方的jar包,或者是之前自己的jar包

这样nexus的私服就搭建完成了,后面我们还需要配置一下maven的setting.xml文件,来使用nexus私服

打开maven的setting文件

<servers>下配置,设置如果需要连接到远程服务器使用的用户名和密码

<server>   
    <id>nexus-releases</id>   
    <username>admin</username>   
    <password>admin123</password>   
</server>
<server>   
    <id>nexus-snapshots</id>   
    <username>admin</username>   
    <password>admin123</password>   
</server>

<mirrors>下配置,设置maven仓库的镜像为我们刚刚安装好的nexus私服

<mirror>
    <id>nexus</id>
    <mirrorof>*</mirrorof>
    <url>http://www.lhsxpumps.com/_localhost:8081/nexus/content/groups/public/</url>
</mirror>

<profiles>下配置,添加仓库信息

<profile>
  <id>nexus</id>
  <repositories>
    <repository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
  </repositories>
 <pluginrepositories>
    <pluginrepository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </pluginrepository>
  </pluginrepositories>
</profile>

再添加下面配置激活仓库

<activeprofiles>
    <activeprofile>nexus</activeprofile>
</activeprofiles>

到此配置完成,重启服务后将我们的maven项目更新后,再进入私服页面会发现下载了我们项目中使用的jar包

但是这样我们之前的jar包仍然没有加入到私服中,我们需要手动添加jar包到私服中

打开我们的3rd party仓库,选择artifact upload来添加jar包

上传成功后就可以在browse index中刷新看到我们刚刚添加的jar包,右侧就是maven中pom.xml的配置,直接复制过去就好,这样我们就完成了上传jar包到私服,配置到项目中

之后我们可以将maven本地仓库 .m2中的错误的jar包删除重新构建项目,这样项目的依赖应该就完成了,不会有找不到jar包的错误了。

如果没有用到maven上找不到的jar包,只是某些jar包下载慢或者下载失败的话,可以尝试使用国内的镜像,比如阿里的镜像等,如果还是失败可以使用私服。

吐槽下钉钉上下载的jar包名字 taobao-sdk-java-auto_1479188381469-20180919 能不能规范点。。。

目前只是将项目的依赖整理完了,目前项目还是使用ant的打包方式,后续应该会使用maven打包或者maven使用ant打包插件的方式打包

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网