Maven私服搭建

最近在公司架构组,由于需要为公司搭建基础开发环境。需要搭建各种开发环境,这里从基础的maven私服搭建分享,(我们这边服务器windowserver的)

第一:下载nexus-3.9.0-01-win64(https://www.sonatype.com/download-nexus-repo-oss 超级慢),备份了一个网盘地址:链接:https://pan.baidu.com/s/1FC95bivQmwy2NWwVkxbG7g 
提取码:w1u9 

下载完成解压后目录如下:

  E:\nexus-3.9.0-01-win64\nexus-3.9.0-01   进入bin 目录 进行启动  nexus.exe  /run   centos7 启动类时  ./nexus.exe  /run

  也可以通过 /etc 目录下的 nexus-default.properties 进行修改 端口号等配置信息

  E:\nexus-3.9.0-01-win64\sonatype-work   存放 文件的目录

启动后,在 http://127.0.0.1:8081/   账号/密码   默认:admin/admin123

Maven用到的Repositories说明

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

maven-releases:私库发行版jar

maven-snapshots:私库快照(调试版本)jar

maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

如果不够用,自己也可以根据博文上面的仓库类型进行选用创建

仓库类型主要分为三种 : proxy(远程代理仓库jar放置的目录)   hosted(本地仓库jar放置的目录)   group(远程和本机)

 

配置ali的maven镜像,提高速度 (代理库)

选择 maven2(proxy)

保存后,在group中加入ali镜像,找到maven-public的group仓库 , 点右边的>进入修改

 

私有仓库(hosted)不用创建 , 使用原有的 maven-releases 和 maven-snapshots即可

 

具体使用:

打包本地jar包私服:1.  需要配置maven的setting.xml 文件 在servers 标签中添加配置

<servers>	
<server>
	 <!-- 与 pom文件中的 distributionManagement id对应 -->
		<id>nexus-releases</id>
		<username>admin</username>
		<password>admin123</password>
    </server>
	

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

	
  </servers>

2,。在项目中配置  需要在 pom文件中配置加入:

 <!-- 发布到中央仓库需要配置  -->
    <distributionManagement>
        <repository>
            <!-- 与 maven setting 文件中的 server id对应 -->
            <id>nexus-releases</id>
            <url>http://127.0.0.1:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>

最后直接进行 发布打包 执行 mvn clean package -Dmaven.test.skip=true deploy  执行成功就会在 私服中看到

这里打包完成!

需要在其他项目中使用这个jar 也需要配置: 先要引入jar包,然后需要在 pom文件中添加资源地址

   <!-- 从中央仓库拿 -->
   <repositories>
       <repository>
           <id>local-center</id>
           <url>http://127.0.0.1:8081/repository/maven-public/</url>
           <releases>
               <enabled>true</enabled>
           </releases>
           <snapshots>
               <enabled>true</enabled>
           </snapshots>
       </repository>
   </repositories>

也可以在maven的setting.xml中配置 (推荐使用) 两种选其一即可

  <profiles>
  
		<profile>
            <id>local-center</id>
            <repositories>
                <repository>
                    <id>nexus-releases</id>
                    <name>nexus-releases</name>
                    <url>http://127.0.0.1:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <name>nexus-releases</name>
                    <url>http://127.0.0.1:8081/repository/maven-public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
  </profiles>
   |
  <activeProfiles>
	 
	 <activeProfile>local-center</activeProfile>
  </activeProfiles>

第一次也这种文章 希望记录下这些使用心得 方便共同学习交流!

  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值