(1)下载 (2)解压缩
[root@node app]# tar -zxvf nexus-3.20.1-01-unix.tar.gz
解压缩得到两个文件夹:nexus-3.20.1-01、sonatype-work。 nexus-3.20.1-01是安装目录,包含了nexus应用程序,和所有运行nexus需要的依赖组件。 sonatype-work是数据目录,包含了nexus管理的所有存储库、组件和其他数据。 (3)启动
[root@node nexus-3.20.1-01]# bin/nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
[root@node nexus-3.20.1-01]# bin/nexus status
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
nexus is running.
[root@node nexus-3.20.1-01]#
(1)登录 通过浏览器打开对应的页面 http://ip:8081/
(2)通过提示,查找admin的密码
[root@node nexus-3.20.1-01]# cat /tpdata/sonatype-work/nexus3/admin.password
25a0febf-f347-466c-a43a-9bbaf86863ef
(3)按照提示修改密码
(4)确认匿名访问
(1)新建库repositoty 左侧菜单Repository>Repositories
(2)选择maven2(proxy)
(3)录入名称和URL
(4)滚动到页面最下方,点击“Create repositoty”按钮
(5)查询新建的库 左侧菜单Repository>Repositories,可以看到新建的maven-aliyun库
(6)配置maven-public组 重新配置maven-public组,使其包含新建的aliyun-maven
(6)负责maven-public组地址
(1)查看Idea的Maven配置文件
(2)编辑settings.xml文件
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexusMaven</id>
<name>nexus maven</name>
<url>http://10.17.xx.xxx:8081/repository/maven-public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
(3)说明 maven配置私服下载有两种方式
本文配置的全局模式。
(1)新建一个Maven项目 (2)构建项目 单击右下方进度条,展开后可以看到构建细节,发现本项目已经从刚才配置的Maven私服下载依赖的Jar包。
(3)查看Maven私服中maven-public组已经下载的Jar
http://ip:8081/service/rest/repository/browse/maven-public/
(1)Nexus本地仓库介绍
(2)配置setting.xml Nexus的仓库对于匿名用户是只读的。为了能够部署构件,还需要在setting.xml中的servers配置认证信息。
<server>
<id>nexus_release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus_snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
(3)配置pom.xml 配置自动部署构件 在pom.xml 中的 project 内添加自动部署构件配置
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://IP:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://IP:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
(4)编写测试类
package com.example.demonexus.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String getMessage(){
return "Hello,World!";
}
}
(5)发布
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ demo-nexus ---
[INFO] Building jar: D:\IdeaProjects\demo-nexus\target\demo-nexus-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:repackage (repackage) @ demo-nexus ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ demo-nexus ---
[INFO] Installing D:\IdeaProjects\demo-nexus\target\demo-nexus-0.0.1-SNAPSHOT.jar to D:\Users\chengyq\.m2\repository\com\example\demo-nexus\0.0.1-SNAPSHOT\demo-nexus-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\IdeaProjects\demo-nexus\pom.xml to D:\Users\chengyq\.m2\repository\com\example\demo-nexus\0.0.1-SNAPSHOT\demo-nexus-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ demo-nexus ---
Downloading from maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/maven-metadata.xml
Uploading to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/demo-nexus-0.0.1-20200121.073808-1.jar
Uploaded to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/demo-nexus-0.0.1-20200121.073808-1.jar (19 MB at 20 MB/s)
Uploading to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/demo-nexus-0.0.1-20200121.073808-1.pom
Uploaded to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/demo-nexus-0.0.1-20200121.073808-1.pom (2.3 kB at 40 kB/s)
Downloading from maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/maven-metadata.xml
Uploading to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/0.0.1-SNAPSHOT/maven-metadata.xml (771 B at 8.2 kB/s)
Uploading to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/maven-metadata.xml
Uploaded to maven-snapshots: http://10.17.12.160:8081/repository/maven-snapshots/com/example/demo-nexus/maven-metadata.xml (281 B at 5.6 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.930 s
[INFO] Finished at: 2020-01-21T15:38:09+08:00
[INFO] ------------------------------------------------------------------------
(6)查看发布的Jar包