使用Nexus搭建Maven私服

最近公司决定要使用Maven私服,让我学习搭建一下,从网上找了一些资料整理了一下,成功搭建了一个Maven私服。

下面分享一下我整理的大概的搭建步骤。

经过查找资料发现目前主流Maven私服是采用的Nexus来搭建的,所以下面使用的就是 Nexus搭建步骤。

一、Maven私服搭建步骤
   1、去官网下载Nexus Bundle版(含jetty服务器) https://www.sonatype.com/download-oss-sonatype
   2、windows系统版本,解压文件,使用DOS窗口 进入bin目录下 执行 nexus.bat install 安装服务
   3、执行 nexus.bat start 启动服务
   4、Linux系统版本, tar解压文件。如果在root用户下,需要先设置环境变量 vi /ect/profile  增加  export RUN_AS_USER=root  
   5、然后执行 去nexus-2.14.4-03\bin\目录下 执行./nexus start 命令
        下载的这个nexus是在jetty上运行的  端口什么就是在 nexus-2.14.4-03/conf/nexus.properties 这个配置文件里

        # Jetty section
	application-port=8081                     #nexus的访问端口配置
	application-host=0.0.0.0                  #nexus主机监听配置
	nexus-webapp=${bundleBasedir}/nexus       #nexus工程目录
	nexus-webapp-context-path=/nexus          #nexus的web访问路径

	# Nexus section
	nexus-work=${bundleBasedir}/../sonatype-work/nexus     #nexus仓库目录
	runtime=${bundleBasedir}/nexus/WEB-INF           #nexus运行程序目录

	# orientdb buffer size in megabytes
	storage.diskCache.bufferSize=4096  

   6、打开 http://127.0.0.1:8081/nexus  (Linux下需要关闭防火墙)
   7、点击右上角 Log In 登录 (默认的账号密码:admin/admin123)  可以点击用户->打开Profile->Change Password
   8、选择Views/Repositories下面Repositories
        主要仓库介绍
            Public Repositories        group        仓库组
            3rd party                  hosted       无法从公共仓库获得的第三方发布版本的构件仓库
            Apache Snapshots           proxy        用了代理ApacheMaven仓库测试版本的构件仓库
            Central                    proxy        用来代理maven中央仓库中发布版本构件的仓库
            Central M1 shadow          virtual      用于提供中央仓库中M1格式的发布版本的构件镜像仓库
            Releases                   hosted       用来部署管理内部的发布版本构件的宿主类型仓库
            Snapshots                  hosted       用来部署管理内部的测试版本构件的宿主类型仓库
        仓库Tpye介绍
            group    仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组
            hosted   本地代理仓库,通常我们会部署自己的构件到这一类型的仓库
            proxy    代理的远程仓库,它们被用来代理远程的公共仓库,如maven中央仓库
            virtual  这种是maven1的,很少会用到
    9、点击Central,选择Configuration  将 Download Remote Indexs 修改为True,然后 save


二、Maven的settings.xml配置
    1、本地仓库配置

       <localRepository>C:\repository</localRepository>  

    2、连接私服的账号密码配置

       <servers>
	    <server>
		<id>releases</id>
		<username>admin</username>
		<password>admin123</password>
	    </server>
	    <server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	    </server>
	</servers>
    3、配置镜像  这里配置mirrorOf的值为*,代表maven的所有访问请求都会指向到Nexus仓库组
   <mirror>
        <id>central</id>
        <mirrorOf>*</mirrorOf>
        <url>http://localhost:8081/nexus/content/groups/public/</url>
   </mirror>
    4、仓库信息配置
      <profiles>
            <profile>
                <!-- profile的id -->
                <id>nexus</id>
                <repositories>
                    <repository>
                        <!--仓库id,repositories可以配置多个仓库,保证id不重复-->
                        <id>nexus</id>
                        <name>Nexus</name>
                        <!--仓库地址,即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>
    5、激活profile
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>

三、pom.xml文件配置
    1、配置文件上传路径
<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>

参考资料:

        https://my.oschina.net/liangbo/blog/195739

        http://www.jianshu.com/p/e4a3ab0298df

        http://blog.csdn.net/catoop/article/details/50779904

        https://xiaobailong24.me/2016/10/11/Blog-Maven/

        http://www.cnblogs.com/dreamroute/p/5440419.html


       

              



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值