下载安装nexus
下载地址:https://www.sonatype.com/download-oss-sonatype
安装地址:https://help.sonatype.com/display/NXRM3/Installation
命令:sh bin/nexus(安装目录的bin目录) start | restart | stop
可以将bin设置到path环境。
- 访问
![这里写图片描述](https://img-blog.csdn.net/20170817105406108?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
默认用户名/密码:admin/admin123
![这里写图片描述](https://img-blog.csdn.net/20170817105630128?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
这里有几种类型的仓库:
1, group: 是群组仓库,就是多个仓库的一个组合包;(可以是hosted,proxy仓库的组合)
2, proxy: 代理仓库,例如:central 中央仓库,当本地仓库访问时,会将请求转发到中央仓库;
3, hosted: 私有(本地仓库),就是自己提供的仓库,例如:第三方包的仓库,自行管理;
可以自行添加、修改、删除仓库(这里不做介绍,so easy,按照界面操作一下就可以搞定)
配置私服环境
前一篇,讲述了maven仓库的基本内容,私服的概念这里就不累赘了。我们可以通过两种方式来达到私服提供maven服务的效果。
1、设置私有仓库;
2、设置镜像仓库;
设置私服仓库
<repositories>
<repository>
<id>nexus-private-repo</id>
<name>learn nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<profiles>
<profile>
<id>nexus-private-repo</id>
<repositories>
<repository>
<id>nexus-private-repo</id>
<name>learn nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-private-repo</activeProfile>
</activeProfiles>
使用镜像模式
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>*</mirrorOf>
<name>Mirror implements private store</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
案例测试
下载
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>study.wzp.maven</groupId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-nexus</artifactId>
<repositories>
<repository>
<id>nexus-private-repo</id>
<name>learn nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
</dependency>
</dependencies>
</project>
![这里写图片描述](https://img-blog.csdn.net/20170817153536255?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>nexus-private-repo-profile</id>
<repositories>
<repository>
<id>nexus-private-repo</id>
<name>nexus private repository test</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-private-repo-profile</activeProfile>
</activeProfiles>
</settings>
![这里写图片描述](https://img-blog.csdn.net/20170817154204209?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus-private-repo</id>
<name>nexus private repository test</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
![这里写图片描述](https://img-blog.csdn.net/20170817154656427?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
发布上传
所谓的发布上传,目的就是将自己开发的项目发布到nexus,然后提供给其他项目使用;
增加发布时的仓库配置:
<distributionManagement>
<repository>
<id>releases</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>
配置服务器的权限:
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
- mvn deploy
![这里写图片描述](https://img-blog.csdn.net/20170817160409866?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJvZ3JhbV9yZWQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)