安装Nexus
(安装Nexus前提是已经安装完jdk)
1. 下载安装包
(由于官网似乎不太行,所以我找了一个版本不是很新的,nexus-2.12.0-01-bundle)
网盘链接: https://pan.baidu.com/s/1umMVkx6FOcVKQ54eu8LeBA 提取码: nki3
2. 解压到任意一个非中文目录下
3.进入文件夹内选择自己系统对应的版本
这里我是win10 64所以就进最后一个。
4. 安装服务并启动
(双击如果不行,就用管理员权限打开,有些电脑设置的权限问题。)
5. 查看Nexus网页服务
在做完前两步后,就可以在浏览器输入http://localhost:8081/nexus访问nexus了
默认登入账号:密码 = admin :admin123
6. 配置文件的地址
可以进入配置文件修改端口号等(默认8081)
7.刚登入时候是什么也没的仓库,需要配置建立索引才能完成搜索功能
ps:这里下载可能有点慢
8. 以上弄完基本的就好了,剩下的就maven连接私服了
配置maven的settings.xml文件
添加本地仓库位置:
<localRepository>F:/Maven/repository</localRepository>
添加server
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
添加mirror
<mirror>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/groups/public</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/apache-snapshots/</url>
<mirrorOf>*</mirrorOf>
</mirror>
添加profile
<!--JDK 配置 -->
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<!-- nexus 配置 -->
<profile>
<id>nexusTest</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
这里nexus配置的是公共库的地址,相当于需要寻找jai包时,本地没有就去公共库中找,没有再去下载。
配置激活profile
<!-- 激活 id 为 nexusTest 的 profile -->
<activeProfiles>
<activeProfile>nexusTest</activeProfile>
</activeProfiles>
到此maven settings就完成了
9.创建maven项目后在pom文件中添加私服的仓库位置
进入nexus中点击左侧的Repositoriespositories,然后点击右侧Releases,再点击右下的summary可以看见(snapshots同理)
然后在maven的pom文件中添加
<distributionManagement>
<repository>
<id>releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
这里的id 一定要和server的一样,不然就找不到登入的账号密码
在创建完项目,想上传私服的话就run as – maven build ,在goals中输入deploy 然后run 就好了。