使用nexus搭建个人maven仓库

前言

这篇文章记录下我在Linux14下,使用nexus搭建私人maven仓库的过程。

安装

下载

https://www.sonatype.com/download-oss-sonatype网页上显示的3.x不支持maven,所以下载了2.x。

解压

tar -zxvf nexus-2.14.1-01-bundle.tar.gz 解压,把bin目录添加到PATH
环境变量

运行

nexus start(/restart/stop) 运行nexus
在网页里输入网址 http://mabinbin.com:8081/nexus/ 登录,点击右上角log in登录,默认账号为admin,默认密码为admin123

配置

登录后网页是这个样子的
这里写图片描述
右上角的列表就是nexus已经添加的仓库,我就使用3rd party。
注意:看到图片里注解3处Repository Policy选择Release,这个仓库只能管理release的组件,不能管理snapshot的组件,如果你要上传项目,pom.xml里面version节点里包含SNAPSHOT则会失败。

部署项目到仓库,通过网页

点击图片里注解4处的Artifacr Upload上传

部署项目到仓库,通过mvn命令

  • 1 在pom.xml里配置上传的仓库
<?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>net.qingtian.maven</groupId>
    <artifactId>upload2</artifactId>
    <version>0.5</version>
    <packaging>jar</packaging>
    <distributionManagement>
        <repository>
            <id>thirdparty</id>
            <name>name_thirdparty</name>
            <url>http://mabinbin.com:8081/nexus/content/repositories/thirdparty</url>
        </repository>
    </distributionManagement>
</project>
  • 2 在~/.m2/setting.xml 添加server节点,添加账号密码,注意server里的id和上面distributionManagement里仓库的id对应
<settings>
    <servers>
        <server>
          <id>thirdparty</id>
          <username>admin</username>
          <password>admin123</password>
        </server>
    </servers>
</settings>
  • 3 在项目根目录下执行 mvn deploy 部署到仓库

使用刚才添加的jar包

  • 1 在~/.m2/setting.xml 添加repository节点
<settings>
    <profiles>
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://mabinbin.com:8081/nexus/content/repositories/thirdparty/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <servers>
        <server>
          <id>thirdparty</id>
          <username>admin</username>
          <password>wodemima</password>
        </server>
    </servers>
</settings>
  • 2 在pom.xml添加依赖
<?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>net.qingtian.maven</groupId>
    <artifactId>download</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>net.qingtian.maven</groupId>
            <artifactId>upload2</artifactId>
            <version>0.5</version>
        </dependency>
    </dependencies>
</project>

参考

http://maven.apache.org/plugins/maven-deploy-plugin/usage.html

Maven学习 (四) 使用Nexus搭建Maven私服

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值