Nexus 3.19.1
文档https://help.sonatype.com/learning/repository-manager-3
wget https://sonatype-download.global.ssl.fastly.net/nexus/3/latest-unix.tar.gz
tar -zvxf nexus-3.19.1-01-unix.tar.gz -C /usr/local/
vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_231
export NEXUS_HOME=/usr/local/nexus/nexus-3.19.1-01
export PATH=$PATH:$JAVA_HOME/bin:$NEXUS_HOME/bin
source /etc/profile
nexus -v
[root@VM_0_8_centos opt]# nexus -v
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Usage: /usr/local/nexus/nexus-3.19.1-01/bin/nexus {start|stop|run|run-redirect|status|restart|force-reload}
在bin目录下和启动程序nexus同级 vi nexus 493行
run_as_root=false
通过从命令行运行文件nexus来启动NXRM
nexus run
[root@VM_0_8_centos bin]# nexus run
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000074f550000, 1890254848, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1890254848 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/nexus/nexus-3.19.1-01/hs_err_pid11022.log
内存不足
vi nexus.vmoptions 虚拟机配置
使用run命令启动存储库管理器将使其在当前shell中运行并显示日志输出。
启动,完成后,日志文件将显示一条消息“ Started Sonatype Nexus”
打开浏览器,然后输入URL:http:// localhost:8081 /。显示Nexus Repository Manager欢迎屏幕。
首次登录NXRM将使用默认的用户名和密码 默认用户名“ admin ”和默认密码“ admin123”
Your admin user password is located in
/usr/local/nexus/sonatype-work/nexus3/admin.password on the server.
由于访问中央仓库有时候会比较慢,这里我添加一个阿里云的代理仓库,然后优先级放到默认中央库之前,, 阿里云的maven仓库url为http://maven.aliyun.com/nexus/content/groups/public
然后在maven-public组里面讲这个aliyun-proxy仓库加入,排在maven-central之前即可。
在maven的默认配置settings.xml中
<servers>
<server>
<id>maven-releasesid>
<username>adminusername>
<password>admin123password>
server>
<server>
<id>maven-snapshotsid>
<username>adminusername>
<password>admin123password>
server>
servers>
<mirrors>
<mirror>
<id>nexus3id>
<mirrorOf>*mirrorOf>
<url>http://122.51.144.43:8081/repository/maven-public/url>
mirror>
mirrors>
<profiles>
<profile>
<id>nexus3id>
<repositories>
<repository>
<id>maven-publicid>
<url>http://122.51.144.43:8081/repository/maven-public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-publicid>
<url>http://122.51.144.43:8081/repository/maven-public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
<updatePolicy>alwaysupdatePolicy>
snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>nexus3activeProfile>
activeProfiles>
如果要发布自己的jar到私服,就需要修改工程的pom.xml,添加如下内容,否则什么都不用做:
<distributionManagement>
<repository>
<id>maven-releasesid>
<name>maven-snapshotsname>
<url>http://122.51.144.43:8081/repository/maven-releases/url>
repository>
<snapshotRepository>
<id>maven-snapshotsid>
<name>maven-snapshotsname>
<url>http://122.51.144.43:8081/repository/maven-snapshots/url>
snapshotRepository>
distributionManagement>
注意上面的repository的id值一定要跟settings.xml文件中配置的server一致。
上传到Nexus上,使用 mvn deploy 即可,开发的时候请使用snapshot版本,也就是version的后缀必须是-SNAPSHOT。
repository就是直接配置站点地址,mirror则是作为站点的镜像,代理某个或某几个站点的请求,实现对repository的完全代替。
可以配置多个repository:
1.配置多个profile,需要配置activeProfiles使配置生效。
2.在同一个profile中配置多个repository。
实现了多站点的配置。下载依赖时,maven会按照配置从上到下的顺序,依次尝试从各个地址下载,成功下载为止。
默认情况下配置多个mirror的情况下,只有第一个生效。
mirrorOf 标签里面放置的是 repository 配置的 id,为了满足一些复杂的需求,Maven还支持更高级的镜像配置:
external:* = 不在本地仓库的文件才从该镜像获取
repo,repo1 = 远程仓库 repo 和 repo1 从该镜像获取
*,!repo1 = 所有远程仓库都从该镜像获取,除 repo1 远程仓库以外
* = 所用远程仓库都从该镜像获取
配置nexus之类私服,可以直接配置成repository, 这样即使配置的这些仓库有些问题导致一些包下不下来,也可以继续用别的仓库尝试。
<settings xmlns="http://maven.apache.org/SETTINGS/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/4.0.0 http://maven.apache.org/xsd/settings-4.0.0.xsd">
<localRepository>D:\maven-repositorylocalRepository>
<offline>falseoffline>
<servers>
<server>
<id>publicid>
<username>developerusername>
<password>xxpassword>
server>
<server>
<id>releasesid>
<username>developerusername>
<password>xxpassword>
server>
<server>
<id>snapshotsid>
<username>developerusername>
<password>xxpassword>
server>
<server>
<id>maven-releasesid>
<username>adminusername>
<password>xxpassword>
server>
<server>
<id>maven-snapshotsid>
<username>adminusername>
<password>xxpassword>
server>
servers>
<mirrors>
<mirror>
<id>nexus-aliyunid>
<name>Nexus aliyunname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
<mirrorOf>centralmirrorOf>
mirror>
<mirror>
<id>nexus-Mavenid>
<name>Nexus Mavenname>
<url>http://central.maven.org/maven2/url>
<mirrorOf>centralmirrorOf>
mirror>
mirrors>
<profiles>
<profile>
<id>devid>
<repositories>
<repository>
<id>publicid>
<url>http://xx.xx.xx.xx/nexus/content/groups/public/url>
<snapshots>
<enabled>trueenabled>
<updatePolicy>alwaysupdatePolicy>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>publicid>
<url>http://xx.xx.xx.xx/nexus/content/groups/public/url>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
profile>
<profile>
<id>nexus3id>
<repositories>
<repository>
<id>maven-publicid>
<url>http://xx.xx.xx.xx:8081/repository/maven-public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
<updatePolicy>alwaysupdatePolicy>
snapshots>
repository>
repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-publicid>
<url>http://xx.xx.xx.xx:8081/repository/maven-public/url>
<releases>
<enabled>trueenabled>
releases>
<snapshots>
<enabled>trueenabled>
snapshots>
pluginRepository>
pluginRepositories>
profile>
profiles>
<activeProfiles>
<activeProfile>devactiveProfile>
<activeProfile>nexus3activeProfile>
activeProfiles>
settings>
编译 + source 源码
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<version>3.5.1version>
<configuration>
<source>${java.version}source>
<target>${java.version}target>
<encoding>${java.encoding}encoding>
configuration>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-source-pluginartifactId>
<configuration>
<attach>trueattach>
configuration>
<executions>
<execution>
<phase>compilephase>
<goals>
<goal>jargoal>
goals>
execution>
executions>
plugin>
plugins>
build>
上传到私服
mvn -DskipTests=true deploy