maven私服

1、简介

maven仓库分为本地仓库和远程仓库,而远程仓库又分为maven中央仓库、其他远程仓库和私服(私有服务器)。其中,中央仓库是由maven官方提供的,而私服就需要我们自己搭建了。

maven私服就是公司局域网内的maven远程仓库,每个员工的电脑上安装maven软件并且连接maven私服,程序员可以将自己开发的项目打成jar并发布到私服,其它项目组成员就可以从私服下载所依赖的jar。私服还充当一个代理服务器的角色,当私服上没有jar包时会从maven中央仓库自动下载。

nexus 是一个maven仓库管理器(其实就是一个软件),nexus可以充当maven私服,同时nexus还提供强大的仓库管理、构件搜索等功能。

搭建maven私服

1、下载nexus:https://help.sonatype.com/repomanager2/download/download-archives---repository-manager-oss

2、安装nexus

将下载的压缩包进行解压,进入bin目录。打开cmd窗口并进入上面bin目录下,执行nexus.bat

install命令安装服务(注意需要以管理员身份运行cmd命令)

进入启动列表,启动nexus服务

3、登录

http://localhost:8081/nexus

点击右上角的log in进行登录,用户名:admin,密码:admin123

4、nexus仓库类型

通过仓库列表可以看到,nexus默认内置了很多仓库,这些仓库可以划分为4种类型,每种类型的仓库用于存放特定的jar包,具体说明如下:

hosted,宿主仓库,部署自己的jar到这个类型的仓库,包括Releases和Snapshots两部分,Releases为公司内部发布版本仓库、 Snapshots为公司内部测试版本仓库

proxy,代理仓库,用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件

group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组

virtual(虚拟):兼容Maven1版本的jar或者插件.

5、nnexus仓库类型与安装目录对应关系

6、将项目发布到maven私服

1)配置maven的settings.xml文件

2)配置项目的pom.xml文件

注意:pom.xml文件的<id>的值和前面配置的settings.xml 文件的<id>值需要一致

<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>

3)执行mvn deploy命令

7、从私服下载jar到本地仓库

1)在maven的settings.xml文件中配置下载模板

2)在maven的settings.xml文件中配置激活下载模板

<profile>

<id>dev</id>

    <repositories>

<repository>       

<id>nexus</id>

<!--仓库地址,即nexus仓库组的地址-->     

<url>http://localhost:8081/nexus/content/groups/public/</url>   

<!--是否下载releases构件-->   

<releases>         

<enabled>true</enabled>   

</releases>   

<!--是否下载snapshots构件-->

<snapshots>

<enabled>true</enabled>           

</snapshots>     

</repository>   

    </repositories> 

  <pluginRepositories> 

<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 --> 

<pluginRepository>     

<id>public</id> 

<name>Public Repositories</name>

<url>http://localhost:8081/nexus/content/groups/public/</url>

</pluginRepository>

  </pluginRepositories>

</profile>

  </profiles>

  <activeProfiles>

  <activeProfile>dev</activeProfile>

</activeProfiles>

</settings>


3)在pom中添加jar的GAV

8、将第三方jar安装到本地仓库

mvn install:install-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 –

Dversion=10.2.0.4.0 -Dpackaging=jar

9、 将第三方jar安装到maven私服

1)在maven的settings.xml配置文件中配置第三方仓库的server信息

2)执行mvn deploy命令进行安装

mvn deploy:deploy-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 –Dversion=10.2.0.4.0 -Dpackaging=jar –

Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

3)位置

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 目前版本已经更新到了3.X下载地址:https://www.sonatype.com/download-oss-s...
    yunqing_71阅读 2,616评论 0赞 0
  • 介绍 私服的优点:解决中央仓库网络、重复下载、本公司非公开组件多项目依赖等问题。 在团队协作开发中,为了提高开发效...
    madfrog_hc阅读 9,053评论 0赞 7
  • 私服的安装、启动、使用 公司在自己的局域网内搭建自己的远程仓库服务器,称为私服,私服服务器即是公司内部的 mave...
    哈哈大圣阅读 3,194评论 0赞 7
  • Maven私服搭建- nexus公司内部搭建。测试团队,运维团队,开发团队,所有团队共用。私服本身也是一个公司内的...
    神豪VS勇士赢阅读 538评论 0赞 0
  • 搭建环境 平台:阿里云 系统:CentOS 7 应用:Nexus 2.x Nexus 私服的安装 Nexus 下载...
    一世梦魇阅读 4,657评论 0赞 1

友情链接更多精彩内容