1.nexus下载
下载地址:https://www.sonatype.com/download-oss-sonatype
2.安装nexus服务
nexus.exe /install <optional-service-name> //安装nexus服务
3.启动和关闭nexus服务
#启动
net start nexus
#关闭
net stop nexus
4.进入管理界面
默认端口为8081,浏览器访问:127.0.0.1:8081,
登录账号:admin
默认密码:admin123
5.仓库类型
6.创建宿主仓库
6.添加用户
7.maven配置文件setting.xml
servers节点添加 id 和私服账号
<servers>
<server>
<id>maven-test-releases</id>
<username>ke****yu</username>
<password>keke0123</password>
</server>
<server>
<id>maven-test-snapshot</id>
<username>ke****yu</username>
<password>keke0123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-test-releases</id>
<mirrorOf>*</mirrorOf>
<name>maven-test-releases</name>
<url>http://127.0.0.1:8081/repository/maven-test-release/</url>
</mirror>
<mirror>
<id>maven-test-snapshot</id>
<mirrorOf>*</mirrorOf>
<name>maven-test-snapshot</name>
<url>http://127.0.0.1:8081/repository/maven-test-snapshot/</url>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
8.项目文件pom.xml
<distributionManagement>
<repository>
<id>maven-test-releases</id>
<name>maven-test-releases</name>
<url>http://127.0.0.1:8081/repository/maven-test-release/</url>
</repository>
<snapshotRepository>
<id>maven-test-snapshot</id>
<name>maven-test-snapshot</name>
<url>http://127.0.0.1:8081/repository/maven-test-snapshot/</url>
</snapshotRepository>
</distributionManagement>
9.测试依赖
10.导入依赖
其他项目选用之前maven配置文件setting.xml,导入依赖:
<dependency>
<groupId>com.example</groupId>
<artifactId>dubbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
11.上传源码到Maven私服
<!-- 要将源码放上去,需要加入这个插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>