idea+maven(3.x)+nexus(3.x)实现将包提交到本地的仓库[windows环境]

@TOC

目录

一、背景

二、需要的工具

三、配置Nexus和maven

四、配置项目pom

五、得到结果

六、欢迎评价和打赏,谢谢!

一、背景

正常的web开发过程中,常常遇到要手动去将包放到maven仓库中,如果是单机自己开发项目可能还没有那么大的困难,如果是与团队协助那就非常麻烦了,可能需要不断的打包上传到远程的服务器或者私服,这就需要用到maven+nexus来进行上传,而且在Ide中双击就上传了,非常方便!

二、需要的工具

需要的工具如下:

  1. maven3.x ,下载地址:http://maven.apache.org/download.cgi(不会安装的自己百度哈)
  2. nexus3.x ,下载地址:https://www.sonatype.com/download-oss-sonatype(安装自己百度哈)
  3. idea (不提供下载,其他也可以)

三、配置Nexus和maven

关于nexus的安装请参考如下:
nexus安装教程(https://blog.csdn.net/xl_lx/article/details/78563610)
当安装好服务以后,我们打开nexus访问:http://localhost:8081/ 然后登录!(默认账号密码:admin admin123)
然后进入:Repository->Repositories 点击createrepository
在这里插入图片描述
在这里插入图片描述
这里解释一下(从此文copy来的可以详细了解:https://blog.csdn.net/cool_summer_moon/article/details/78779530?utm_source=blogxgwz0):
hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件以及自己或第三方的项目构件;
proxy 代理仓库:代理公共的远程仓库;
group 仓库组:Nexus 通过仓库组统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。

然后我们选择maven2(hosted) 配置如下:
在这里插入图片描述
最后创建create repository
跳回仓库你会发现多了一个test然后你点击maven public 进去做如下操作然后save保存
在这里插入图片描述
最后到user中创建用户(也可以不用创建用默认的admin就可以了,但是如果考虑安全性需要去修改密码,这个麻自己查文章去!)
在这里插入图片描述
点击create local user 创建如下:
在这里插入图片描述
在这里插入图片描述
最后一步我们开始配置maven了
打开maven的config
配置如下:

// 在servicers中添加如下 ,注意啦: 这个id后面是跟我们项目中的要一致,不要搞到最后还来问
//这个 username就是刚才创建的账号 password不用说了吧(密码)
<servers>
	  <server>
      <id>nexus</id>
      <username>dev</username>
      <password>dev123</password>
    </server>
  </servers>
//这个id跟上面的id要一致哦,url一定要是你自己仓库的url如果不清楚去那个仓库里面有个copy出来贴在地址栏里面访问一下如果通了就是对的。
   <mirrors>
	<mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus xunquanbao</name>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
  // 最后这些不解释直接copy吧,建议先跑通再去了解!
  <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>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

在这里插入图片描述

四、配置项目pom

好了以上配置好后,我们就开始创建我们的maven测试项目这个怎么创建我就不演示了,反正就是一个空项目如图:
在这里插入图片描述

// maven配置如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.hong</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version> 1.5.9.RELEASE</version>
            </plugin>
            <!--打包的时候跳过test-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- maven私服地址 这里的id跟maven里面的配置一样哈! -->
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>maven-releases</name>
            <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <name>maven-snapshots</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

</project>

然后呢,你别以后一样跟我运行就可以了,注意要把你的nexus服务重新一下。(怎么装好好看前面文章一样的!)
在这里插入图片描述
然后运行打开idea右边的maven(没有的话自己百度哈)运行deploy

五、得到结果

在这里插入图片描述
可以到nexus上面看到如下:
在这里插入图片描述

本人在这里说下踩过的坑如下:
1.nexus的账号没有配置权限,建议一开始测试用admin测试!
2.没有配置maven的maven-deploy-plugin一直报错:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project test: Failed to deploy artifacts: Could not transfer artifact com.hong:test:jar:1.0-20181028.160554-1 from/to nexus (http://localhost:8081/repository/maven-snapshots/): Failed to transfer file: http://localhost:8081/repository/maven-snapshots/com/hong/test/1.0-SNAPSHOT/test-1.0-20181028.160554-1.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
注意喽,这里的测试了几次都是报一样的错,最后发现没配!用我的配置来跑就没有题了。

六、欢迎评价和打赏,谢谢!

最后说下,下次我将实现远程linux的部署和打包及配置!
如果有不懂请留言,如果觉得本文不错,对你有帮助请打赏,谢谢!
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值