搭建Maven的Nexus3私服
1、常见的Maven私服产品
- Apache的Archiva
- JFrog的Artifactory
- 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
。
λ echo %NEXUS_HOME%
D:\devtools\nexus-3.58.1-02-win64\nexus-3.58.1-02
并将%NEXUS_HOME%\bin
加入Path
。Nexus3
自带了jre
,可以按需替换成其他的版本。
- 修改端口号和
ContextPath
,配置文件路径%NEXUS_HOME%\etc\nexus-default.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-featurenexus.hazelcast.discovery.isEnabled=true
- 修改JVM参数,配置文件路径
%NEXUS_HOME%\etc\nexus.vmoptions
这个可以不改
-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/
λ 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文件里
admin5fe0c78a-f71a-4ad8-80b3-6b63e6f9017f
配置阿里云代理仓库
阿里云Maven仓库配置指南(仓库服务)
阿里云代理maven仓库地址:https://maven.aliyun.com/repository/central
创建仓库
选择maven2(proxy)
创建阿里云代理仓库
已经创建好的仓库
配置仓库组
选择maven-public
保存配置
修改%MAVEN_HOME%/conf/setting.xml
修改servers
和``mirrors`节点配置:
<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构建,配置如下:
<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
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
已经发布至私服。