Nexus是maven仓库管理器,如果你使用maven,你可以从中央仓库下载所需用的构件(artifact),但这通常不是一个好的做法,你应该在本地假设一个maven仓库服务器,在代理远程仓库的同时维护本地仓库,节省时间,减少网络占用,nexus就可以满足这样的需求。
此外nexus还提供了一个强大的仓库管理功能,构件搜索功能,它基于rest,友好的ui是一个extjs的rest客户都安,它占用比较少的内存,基于简单文件系统而非数据库,这些优点使其称为最流行的maven仓库管理器。
nexus不是maven的核心概念,它仅仅是一种衍生出来的特殊maven仓库,对于maven来说,仓库只有两种,本地仓库和远程仓库。
本地仓库就是我们在maven的settings.xml中配置的本地仓库地址,由于最原始的本地仓库是空的,maven必须至少有一个可用的远程仓库,才能执行maven命令下载到所需用的构件,中央仓库是maven默认的远程仓库。
私服是假设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件有了私服之后,当maven需要下载构件时,直接请求私服,私服上存在则下载到本地,否则私服请求到远程中央仓库,将构件下载到私服,再提供给本地仓库下载。
JBoos是一个开放源代码的应用服务器java.net是指java仓库和net仓库。
Host | 网络信息 |
---|---|
Maven | ens33:192.168.43.176 |
Nexus | ens33:192.168.43.104 |
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# iptables-save
[root@localhost ~]# setenforce 0
[root@localhost ~]# tar -zxvf jdk-8u201-linux-x64.tar.gz -C /usr/local/
[root@localhost ~]# vim /etc/profile
添加:
export JAVA_HOME=/usr/local/jdk1.8.0_201/
export JRE_HOME=/usr/local/jdk1.8.0_201/jre
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mkdir /usr/local/nexus
[root@localhost ~]# tar -zxvf nexus-3.14.0-04-unix.tar.gz -C /usr/local/nexus/
[root@localhost ~]# /usr/local/nexus/nexus-3.14.0-04/bin/nexus start
[root@localhost ~]# netstat -anput | grep 8081
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 46686/java
[root@localhost ~]# firefox 192.168.43.104:8081
/usr/local/nexus/nexus-3.14.0-04/ #应用目录。
/usr/local/nexus/sonattpe-work/ #工作目录(主要用于存放镜像仓库)。
/usr/local/nexus/sonattpe-work/nexus3/log #日志目录(存放关于nexus各个模块的日志文件)。
#如果需要备份和迁移镜像仓库,则需要拷贝/usr/local//nexus/sonattpe-work/即可。
[root@localhost ~]# cd /usr/local/nexus/nexus-3.14.0-04/
[root@localhost nexus-3.14.0-04]# java -jar ./lib/support/nexus-orient-console.jar
OrientDB console v.2.2.36 (build d3beb772c02098ceaea89779a7afd4b7305d3788, branch 2.2.x) https://www.orientdb.com
Type 'help' to display all the supported commands.
orientdb> connect plocal:../sonatype-work/nexus3/db/security admin admin
Connecting to database [plocal:../sonatype-work/nexus3/db/security] with user 'admin'...OK
orientdb {db=security}> Update user set password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" upsert where id="admin"
Updated record(s) '1' in 0.026000 sec(s).
orientdb {db=security}> exit
[root@localhost nexus-3.14.0-04]# ulimit -HSn 65536
Host | 网络信息 |
---|---|
Maven | ens33:192.168.43.176 |
Nexus | ens33:192.168.43.104 |
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# iptables-save
[root@localhost ~]# setenforce 0
[root@localhost ~]# cd /usr/local/apache-maven-3.6.0/
[root@localhost apache-maven-3.6.0]# cd conf/
[root@localhost conf]# cp settings.xml settings.bak
删除原先添加的aliyun的mirror。
添加:
nexus
nexus maven
http://192.168.43.104:8081/repository/maven-public/
*
在253行profiles标签里添加:
nexusconf
nexus
http://192.168.43.104:8081/repository/maven-public/
true
true
nexus
http://192.168.43.104:8081/repository/maven-public/
true
true
到288行,删除一个activeProfile,然后取消activeProfiles的注释,把activeProfile标签里的内容改成nexus
nexusconf
[root@localhost conf]# rm -rf /root/.m2/repository/*
[root@localhost conf]# cd /root/bdqnweb/
[root@localhost bdqnweb]# mvn clean package
[INFO] Packaging webapp
[INFO] Assembling webapp [bdqnweb] in [/root/bdqnweb/target/bdqnweb]
[INFO] Processing war project
[INFO] Copying webapp resources [/root/bdqnweb/src/main/webapp]
[INFO] Webapp assembled in [24 msecs]
[INFO] Building war: /root/bdqnweb/target/bdqnweb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 09:17 min
[INFO] Finished at: 2019-11-23T17:31:18+08:00
[INFO] ------------------------------------------------------------------------
[root@localhost bdqnweb]# vim /usr/local/apache-maven-3.6.0/conf/settings.xml
找到133行,在标签内添加:
nexus
dev
admin123
[root@localhost bdqnweb]# vim pom.xml
nexus
Nexus Snapshot
http://192.168.43.104:8081/repository/maven-snapshots/
nexus
Nexus releases
http://192.168.43.104:8081/repository/maven-releases/
[root@localhost bdqnweb]# rm -rf /root/.m2/repository/*
[root@localhost bdqnweb]# mvn deploy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:18 min
[INFO] Finished at: 2019-11-23T21:13:58+08:00
[INFO] ------------------------------------------------------------------------
[root@localhost bdqnweb]# vim pom.xml
删除version标签中的napshots的内容只留一个1.0即可:
[root@localhost bdqnweb]# mvn deploy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.539 s
[INFO] Finished at: 2019-11-23T21:22:44+08:00
[INFO] ------------------------------------------------------------------------
[root@localhost bdqnweb]# vim /usr/local/apache-maven-3.6.0/conf/settings.xml
找到272行在标签内添加:
3rdnexus
http://192.168.43.104:8081/repository/3rd
true
true
找到138行,,在标签里添加:
3rdnexus
dev
admin123
[root@localhost bdqnweb]# mvn deploy:deploy-file -DgroupId=com.aliyun.oss -DartifactId=aliyun-sdk-oss -Dversion=2.6.1 -Dpackaging=jar -Dfile=/root/aliyun-sdk-oss-2.6.1.jar -Durl=http://192.168.43.104:8081/repository/3rd/ -DrepositoryId=3rdnexus
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'enable' (position: START_TAG seen ...\n ... @271:21) @ /usr/local/apache-maven-3.6.0/conf/settings.xml, line 271, column 21
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< cn.bdqn.bdqnweb:bdqnweb >-----------------------
[INFO] Building bdqnweb Maven Webapp 1.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ bdqnweb ---
Uploading to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/2.6.1/aliyun-sdk-oss-2.6.1.jar
Uploaded to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/2.6.1/aliyun-sdk-oss-2.6.1.jar (470 kB at 1.9 MB/s)
Uploading to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/2.6.1/aliyun-sdk-oss-2.6.1.pom
Uploaded to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/2.6.1/aliyun-sdk-oss-2.6.1.pom (401 B at 7.2 kB/s)
Downloading from 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/maven-metadata.xml
Uploading to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/maven-metadata.xml
Uploaded to 3rdnexus: http://192.168.43.104:8081/repository/3rd/com/aliyun/oss/aliyun-sdk-oss/maven-metadata.xml (308 B at 8.8 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.130 s
[INFO] Finished at: 2019-11-23T21:39:08+08:00
[INFO] ------------------------------------------------------------------------
You have new mail in /var/spool/mail/root