搭建Maven的Nexus3私服

搭建Maven的Nexus3私服

1、常见的Maven私服产品

  1. Apache的Archiva
  2. JFrog的Artifactory
  3. Sonatype的Nexus([ˈneksəs])(当前最流行、使用最广泛)

2. windows java8安装和配置私服Nexus3

参考:

https://zhuanlan.zhihu.com/p/665815321

https://blog.csdn.net/jiangyq_/article/details/134823631

下载

下载地址:https://help.sonatype.com/repomanager3/product-information/download

最新版本地址:

https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.67.1-01-java8-win64.zip

安装

  • 解压nexus-3.58.1-02-win64.zip,配置系统环境变量NEXUS_HOME
bash 复制代码
λ echo %NEXUS_HOME%
D:\devtools\nexus-3.58.1-02-win64\nexus-3.58.1-02

并将%NEXUS_HOME%\bin加入PathNexus3自带了jre,可以按需替换成其他的版本。

  • 修改端口号和ContextPath,配置文件路径%NEXUS_HOME%\etc\nexus-default.properties
properties 复制代码
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
# 端口号
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
# ContextPath
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

nexus.hazelcast.discovery.isEnabled=true
  • 修改JVM参数,配置文件路径%NEXUS_HOME%\etc\nexus.vmoptions 这个可以不改
properties 复制代码
-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
-Djdk.tls.ephemeralDHKeySize=2048
#
# additional vmoptions needed for Java9+ 
# Java9以上需要打开以下注释的配置
#
# --add-reads=java.xml=java.logging
# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED
# --patch-module java.base=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.locator-4.3.9.jar
# --patch-module java.xml=${KARAF_HOME}/lib/endorsed/org.apache.karaf.specs.java.xml-4.3.9.jar
# --add-opens java.base/java.security=ALL-UNNAMED
# --add-opens java.base/java.net=ALL-UNNAMED
# --add-opens java.base/java.lang=ALL-UNNAMED
# --add-opens java.base/java.util=ALL-UNNAMED
# --add-opens java.naming/javax.naming.spi=ALL-UNNAMED
# --add-opens java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED
# --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED
# --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED
# --add-exports java.security.sasl/com.sun.security.sasl=ALL-UNNAMED
#
# comment out this vmoption when using Java9+
#
-Djava.endorsed.dirs=lib/endorsed

启动和安装nexus系统服务

这是我见过最傻的!!!

直接输入命令

nexus.exe/run

启动成功

登录http://localhost:8081/

bash 复制代码
λ nexus --help
Usage: nexus.exe /install | /uninstall | /stop | /start | /status | /run | /run-redirect
  • nexus /run 控制台启动
  • nexus /run-redirect 控制台启动可重定向标准输出和错误流到日志文件
  • nexus /install 安装nexus系统服务
  • nexus /uninstall 卸载nexus系统服务
  • nexus /stop 停止nexus系统服务
  • nexus /start 启动nexus系统服务

首次启动后会在%NEXUS_HOME%\sonatype-work\nexus3目录下生成admin.password文件,文件中内容就是admin用户的登陆密码。登陆进去之后会提示修改密码,修改完成之后会移除密码文件。

通过文件内容查看登录密码:

  • 2.x的版本,初始账户和密码分别为admin和admin123

  • 3.x的版本,初始账户是admin,密码在sonatype-work\nexus3\admin.password文件里

    admin

    5fe0c78a-f71a-4ad8-80b3-6b63e6f9017f

配置阿里云代理仓库

阿里云Maven仓库配置指南(仓库服务)

阿里云代理maven仓库地址:https://maven.aliyun.com/repository/central

创建仓库

选择maven2(proxy)

创建阿里云代理仓库

已经创建好的仓库

配置仓库组

选择maven-public

保存配置

修改%MAVEN_HOME%/conf/setting.xml

修改servers和``mirrors`节点配置:

xml 复制代码
<servers>
 
    <server>
      <id>maven-snapshots</id>
      <username>登陆用户</username>
      <password>密码</password>
    </server>
    <server>
      <id>maven-releases</id>
      <username>登陆用户</username>
      <password>密码</password>
    </server>
    <server>
      <id>maven-public</id>
      <username>登陆用户</username>
      <password>密码</password>
    </server>
  </servers>

 
  <mirrors>

    <mirror>
      <id>maven-snapshots</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:10000/nexus/repository/maven-snapshots/</url>
	  <blocked>false</blocked>
    </mirror>
    <mirror>
      <id>maven-releases</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:10000/nexus/repository/maven-releases/</url>
    </mirror>
    <mirror>
      <id>maven-public</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:10000/nexus/repository/maven-public/</url>
    </mirror> 

  </mirrors>

保存文件,至此就全部配置好了。

发布构建

在项目的pom.xml中增加要发布的仓库地址,比如需要发布releases构建,配置如下:

xml 复制代码
    <distributionManagement>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://localhost:10000/nexus/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>maven-releases</id>
            <url>http://localhost:10000/nexus/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

然后执行mvn deploy

bash 复制代码
D:\devtools\workspace\ideaj\nexus3>mvn deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------------< nexus3:nexus3 >----------------------------
[INFO] Building nexus3 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ nexus3 ---
[INFO] Copying 0 resource from src\main\resources to target\classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ nexus3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ nexus3 ---
[INFO] skip non existing resourceDirectory D:\devtools\workspace\ideaj\nexus3\src\test\resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ nexus3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- surefire:3.1.2:test (default-test) @ nexus3 ---
[INFO] No tests to run.
[INFO] 
[INFO] --- jar:3.3.0:jar (default-jar) @ nexus3 ---
[INFO] 
[INFO] --- install:3.1.1:install (default-install) @ nexus3 ---
[INFO] Installing D:\devtools\workspace\ideaj\nexus3\pom.xml to D:\devtools\apache-maven-3.9.4\repository\nexus3\nexus3\1.0-SNAPSHOT\nexus3-1.0-SNAPSHOT.pom
[INFO] Installing D:\devtools\workspace\ideaj\nexus3\target\nexus3-1.0-SNAPSHOT.jar to D:\devtools\apache-maven-3.9.4\repository\nexus3\nexus3\1.0-SNAPSHOT\nexus3-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- deploy:3.1.1:deploy (default-deploy) @ nexus3 ---
Downloading from maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/maven-metadata.xml
Uploading to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/nexus3-1.0-20231108.154630-1.pom
Uploaded to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/nexus3-1.0-20231108.154630-1.pom (1.0 kB at 16 kB/s)
Uploading to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/nexus3-1.0-20231108.154630-1.jar
Uploaded to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/nexus3-1.0-20231108.154630-1.jar (1.4 kB at 22 kB/s)
Downloading from maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/maven-metadata.xml
Uploading to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/maven-metadata.xml
Uploaded to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/1.0-SNAPSHOT/maven-metadata.xml (756 B at 15 kB/s)
Uploading to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/maven-metadata.xml
Uploaded to maven-snapshots: http://localhost:10000/nexus/repository/maven-snapshots/nexus3/nexus3/maven-metadata.xml (270 B at 5.2 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.329 s
[INFO] Finished at: 2023-11-08T23:46:32+08:00
[INFO] ------------------------------------------------------------------------

可以看到nexus3-1.0-SNAPSHOT.jar 已经发布至私服。

相关推荐
计算机毕设指导611 分钟前
基于 SpringBoot 的作业管理系统【附源码】
java·vue.js·spring boot·后端·mysql·spring·intellij-idea
Gu Gu Study13 分钟前
枚举与lambda表达式,枚举实现单例模式为什么是安全的,lambda表达式与函数式接口的小九九~
java·开发语言
Chris _data16 分钟前
二叉树oj题解析
java·数据结构
牙牙70521 分钟前
Centos7安装Jenkins脚本一键部署
java·servlet·jenkins
paopaokaka_luck29 分钟前
[371]基于springboot的高校实习管理系统
java·spring boot·后端
以后不吃煲仔饭41 分钟前
Java基础夯实——2.7 线程上下文切换
java·开发语言
进阶的架构师42 分钟前
2024年Java面试题及答案整理(1000+面试题附答案解析)
java·开发语言
The_Ticker1 小时前
CFD平台如何接入实时行情源
java·大数据·数据库·人工智能·算法·区块链·软件工程
大数据编程之光1 小时前
Flink Standalone集群模式安装部署全攻略
java·大数据·开发语言·面试·flink
爪哇学长1 小时前
双指针算法详解:原理、应用场景及代码示例
java·数据结构·算法