使用 nexus 2 搭建 maven 私服及常见配置

本文介绍 Nexus 的安装与配置过程,包括启动脚本、端口设置、默认账号及密码,如何配置为 Maven 项目的私服仓库,以及如何通过设置镜像加速第三方依赖包的下载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

nexus 下载页面:https://www.sonatype.com/down...
nexus 下载地址:http://www.sonatype.org/downl...

解压后到 bin 目录可以看到启动脚本

./nexus start 启动
./nexus stop 停止
./nexus status 状态

如果启动用户是 root , 需要修改启动脚本 RUN_AS_USER="root"

conf/nexus.properties

application-port=8081  # 端口号
nexus-webapp-context-path=/  #控制域名端口后的应用名
nexus-work=${bundleBasedir}/../sonatype-work/nexus  # jar包存放地址

启动后稍等片刻访问:域名或ip:8081/

默认用户

超级管理员:admin 密码:admin123
部署:deployment 密码:deployment123

为了安全还是尽快更改密码

配置 nexus 仓库

第一步:以超级管理员登录,允许 Central 和 Apache Snapshots 仓库从远程仓库下载索引

clipboard.png

第二步:更改密码,也可以添加用户

新加用户如果想要有 deploy 权限,既要有 Deployment 角色也要有仓库角色,可以参考 deployment 用户的权限

clipboard.png

开机自启

编辑开机启动文件 sudo vim /etc/rc.local

#!/bin/sh -e

su - junbaor -c "sh /home/junbaor/nexus-2.14.4-03/bin/nexus start
exit 0

加执行权限:sudo chmod 755 /etc/rc.local

由于不能用 root 用户启动,所以指定以 junbaor 用户进行启动

配置

加快构建速度

如果是为了加快第三方包下载速度,需要在 maven 的 setting.xml 文件<mirrors>下添加

<mirror>
    <id>central</id>
    <mirrorOf>central</mirrorOf>
    <name>Mirror</name>
    <url>http://oss.junbaor.com:8081/content/groups/public/</url>
</mirror>
上传私服

如果需要上传jar包到私服,需要在 maven 的 setting.xml 文件<servers>下添加

<server>
    <id>nexus-snapshot</id>
    <username>admin</username>
    <password>admin123</password>
</server>
<server>
    <id>nexus-release</id>
    <username>admin</username>
    <password>admin123</password>
</server>

然后在项目的 pom.xml 中添加

<distributionManagement>
    <repository>
        <id>nexus-release</id>
        <name>Nexus Release Repository</name>
        <url>http://oss.junbaor.com:8081/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshot</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://oss.junbaor.com:8081/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

<repositories>
    <repository>
        <id>public</id>
        <name>public</name>
        <url>http://oss.junbaor.com:8081/content/groups/public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

注意:<repository> 的 <id> 需要和 setting.xml 中的 <server> 中的 id 一致

传源码包

如果想要上传源码包需要添加以下插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
        </execution>
    </executions>
</plugin>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值