搭建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 已经发布至私服。

相关推荐
Yaml42 小时前
Spring Boot 与 Vue 共筑二手书籍交易卓越平台
java·spring boot·后端·mysql·spring·vue·二手书籍
小小小妮子~2 小时前
Spring Boot详解:从入门到精通
java·spring boot·后端
hong1616882 小时前
Spring Boot中实现多数据源连接和切换的方案
java·spring boot·后端
aloha_7892 小时前
从零记录搭建一个干净的mybatis环境
java·笔记·spring·spring cloud·maven·mybatis·springboot
记录成长java3 小时前
ServletContext,Cookie,HttpSession的使用
java·开发语言·servlet
睡觉谁叫~~~3 小时前
一文解秘Rust如何与Java互操作
java·开发语言·后端·rust
程序媛小果3 小时前
基于java+SpringBoot+Vue的旅游管理系统设计与实现
java·vue.js·spring boot
小屁孩大帅-杨一凡4 小时前
java后端请求想接收多个对象入参的数据
java·开发语言
java1234_小锋4 小时前
使用 RabbitMQ 有什么好处?
java·开发语言
TangKenny4 小时前
计算网络信号
java·算法·华为