0
点赞
收藏
分享

微信扫一扫

使用 Nexus 搭建 Maven私服仓库

佛贝鲁先生 2022-05-02 阅读 133

下载并解压 nexus

[root@iZuf6i2yvneqsd64c75nm5Z software]# tar -zxvf Nexus-3.21.1-01-unix.tar.gz

解压后,有两个目录:

  • nexus-version
  • sonatype-work
[root@iZuf6i2yvneqsd64c75nm5Z software]# cd nexus-3.21.1-01/
[root@iZuf6i2yvneqsd64c75nm5Z nexus-3.21.1-01]# ll
total 92
drwxr-xr-x  3 root root  4096 Jan  8 22:55 bin
drwxr-xr-x  2 root root  4096 Jan  8 22:21 deploy
drwxr-xr-x  7 root root  4096 Jan  8 22:55 etc
drwxr-xr-x  5 root root  4096 Jan  8 22:21 lib
-rw-r--r--  1 root root   395 Feb 19  2020 NOTICE.txt
-rw-r--r--  1 root root 17321 Feb 19  2020 OSS-LICENSE.txt
-rw-r--r--  1 root root 41954 Feb 19  2020 PRO-LICENSE.txt
drwxr-xr-x  3 root root  4096 Jan  8 22:21 public
drwxr-xr-x 21 root root  4096 Jan  8 22:21 system

启动/停止 nexus

[root@iZuf6i2yvneqsd64c75nm5Z nexus-3.21.1-01]# bin/nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Starting nexus
[root@iZuf6i2yvneqsd64c75nm5Z nexus-3.21.1-01]# bin/nexus stop
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Shutting down nexus
Stopped.
  • 检测是否启动成功:
    • ps aux | grep nexus
    • jps → UnixLauncher

如果失败,并且 nexus 根目录下有 hs_err_pidXXX.log 之类的日志,并且报错:

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1890254848 bytes for committing reserved memory.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2756), pid=21219, tid=0x00007f7498513700
#
# JRE version:  (8.0_311-b11) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.311-b11 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

则可能是jvm启动参数设置的 -Xmx/-Xms 超过了机器内存。需要修改jvm启动参数:

vim bin/nexus.vmoptions
-Xms512m
-Xmx512m
-XX:MaxDirectMemorySize=512m

访问

默认端口:8081(可在 etc/nexus-default.properties 文件中修改)

地址:http://ip:8081

右上角登录:

  • 默认账户:admin
  • 默认密码:sonatype-work/nexus3/admin.password 文件中

登录成功后修改密码。

使用

编辑本地 maven 的 Settings.xml

配置 servers 内容

<servers>
 <server>
	<id>releases</id>        
	<username>admin</username>   
	<password>密码</password>  
</server>
<server>
	<id>snapshots</id>     
	<username>admin</username> 
	<password>密码</password>   
</server>
</servers>

idea 配置 deploy 时上传到私服

配置 pom.xml

		<distributionManagement>
      <repository>
            <id>releases</id>
            <url>http://xxx:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://xxx:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

maven 执行 deploy 命令,控制台中有以下输出。

Downloading from snapshots: http://xxx:8081/repository/maven-snapshots/com/c/Core/maven-metadata.xml
Uploading to snapshots: http://xxx:8081/repository/maven-snapshots/com/c/Core/1.0-SNAPSHOT/maven-metadata.xml
Uploaded to snapshots: http://xxx:8081/repository/maven-snapshots/com/c/Core/1.0-SNAPSHOT/maven-metadata.xml (753 B at 2.0 kB/s)
Uploading to snapshots: http://xxx:8081/repository/maven-snapshots/com/c/Core/maven-metadata.xml
Uploaded to snapshots: http://xxx:8081/repository/maven-snapshots/com/c/Core/maven-metadata.xml (267 B at 853 B/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.596 s
[INFO] Finished at: 2022-01-08T23:38:14+08:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

在这里插入图片描述

指定maven地址下载jar包到本地

将项目pom.xml文件的repositories标签里添加上

<repository>
    <id>snapshots</id>
    <name>Snapshots Repository</name>
    <url>http://xxx:8081/repository/maven-snapshots</url>
    <snapshots>
	  <enabled>false</enabled>
</repository>
举报

相关推荐

0 条评论