Maven Nexus 私库的搭建

最近需要在服务器搭建私库。就写下可能以后用得到。
具体用到 MavenNexus3.X.
maven-3.3.9 nexus-3.10.0-04 (楼主配置);
maven 的安装就不介绍了。

一.首先安装Nexus

https://www.sonatype.com/download-oss-sonatype
选择对应的操作系统 下载。
然后—>解压。找到
D:\nexus-3.10.0-04-win64\nexus-3.10.0-04\bin (我的安装目录)
这里写图片描述

一般双击exe可以启动。但是这里不起作用。所以。。。

按住shift 鼠标右键 选择在此处打开命令窗口。 当然 cd进来也行。

然后只要在终端输入 nexus /run 就可以运行了。(默认8081端口,后续可以修改)
D:\nexus-3.10.0-04-win64\sonatype-work\nexus3\etc\nexus.properties 修改端口
很多版本说也有 nexus start (都I行) 停止时nexus stop 这些可以自己百度。
打开 http://localhost:8081
这里写图片描述

出现这页面说明服务启动了。。老铁可以的。
然后点击右上角的登录。 账号:admin 密码:admin123 (默认的);

然后出现好多不同类型的库。
nexus的仓库类型分为以下四种:

           group: 仓库组

           hosted:宿主

          proxy:代理

这里写图片描述

好了这就是关系图。 解释下就懂了。

  1. 一般自己的maven配置的 也就是 连接的 是我们私库的 中央库(仓库组)。为什么呢?
  2. 因为如图,仓库组可以包含代理仓库和宿主仓库,代理仓库比如熟悉 的 aliyun
  3. 说到这应该猜到了把?就是说我们maven配置这个仓库组,可以连接代理库拿东西,拿不到的话
    也可以在我们自己的宿主库拿。
  4. 好了。让我们来建几个库来搭建下。至于几个库用来干嘛的。做完后会有个大概的认识。不急。

这里写图片描述
都是选m2的。 每个类型添加一个。
这里写图片描述
这里写图片描述
这里写图片描述

这里写图片描述

扫描二维码关注公众号,回复: 48601 查看本文章

这里写图片描述

然后服务端的配置算初步完成了。可以用了。

二.客户端maven配置根目录Setting.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>E:\testre</localRepository>
  <pluginGroups>  
     <pluginGroup>org.sonatype.plugins</pluginGroup>  
  </pluginGroups>
  <proxies>
  </proxies>

  <servers>
        <server>  
            <id>nexus</id>   //注意和后面的id要匹配
            <username>admin</username>  
            <password>admin123</password>  
        </server>    
  </servers>

  <mirrors>
        <mirror>  //公共仓库组
            <id>nexus</id>  
            <mirrorOf>*</mirrorOf>  
            <url>http://192.168.0.100:8081/repository/nexus-public/</url>  
        </mirror>      
  </mirrors>
   <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> 

</settings>

三.项目pom 中配置

    <distributionManagement>  
        <repository>  
            <id>nexus</id>  
            <name>Releases</name>  
            <url>http://192.168.0.100:8081/repository/nexus-release/</url>  
        </repository>  
        <snapshotRepository>  
            <id>nexus</id>  
            <name>Snapshot</name>  
            <url>http://192.168.0.100:8081/repository/nexus-snapshot/</url>  
        </snapshotRepository>  
    </distributionManagement>  

好了 配置完成。

  • 执行 mvn clean source:jar package
  • 执行 mvn deploy -e
  • 如果在eclipse中 把前面 的 mvn 去掉 不然会报错 不认识 “mvn”。

好了完成了。

猜你喜欢

转载自blog.csdn.net/Alai_programmer/article/details/80050779
今日推荐