安装nexus
下载nexus
访问nexus官方网站http://www.sonatype.org/nexus/,下载nexus-2.9.1-02-bundle.zip。 http://www.sonatype.org/nexus/archived
解压至某个目录(如E:\Eb\nexus-2.9.1-02-bundle)
开启jetty服务器。找到E:\Eb\nexus-2.9.1-02-bundle\nexus-2.9.1-02\bin\jsw\windows-x86-32(由于jdk安装的是32位版本,因此执行此目录下的文件)目录,执行console-nexus.bat批处理文件。
访问nexus管理页面
打开浏览器,输入http://localhost:8081/nexus/,点击页面右上方的Log in超链接,输入默认用户名密码admin/admin123,登录nexus管理页面。
配置nexus
登录nexus管理页面,点击左侧的Repositories,显示相关的仓库信息,各个仓库的含义可自行百度之。
选中Central,点击下方的Configuration选项卡。修改Download Remote Indexes项的值为True。点击页面下方的save按钮。
修改本地目录存储配置
直接修改E:\Eb\nexus-2.9.1-02-bundle\nexus-2.9.1-02\conf\nexus.properties中的配置项nexus-work如下
- # Nexus section
- #nexus-work=${bundleBasedir}/../sonatype-work/nexus
- nexus-work=H:/Eb/nexus-2.9.1-02-bundle/sonatype-work/nexus
- runtime=${bundleBasedir}/nexus/WEB-INF
基本信息
登录成功后,选择左边 Views/Repositories 菜单下的 Repositories,可以看到一些预设的仓库,我们会用到的一般只有 Public Repositories 和 3rd party , Public Repositories 为公共仓库,3rd party 为第三方仓库,可以上传第三方的 Jar (当然也可以是自己封装的 Jar)。
添加阿里云仓库
阿里云的maven仓库地址:
http://maven.aliyun.com/nexus/content/groups/public
nexus里,Public Repositories是对外的出口,实际用了哪个库是在它的Configuration的配置的。
有个Ordered Group Repositories,里面有个Central库,它的
库地址是https://repo1.maven.org/maven2/,速度很慢
快捷方法
直接把Central的地址换成阿里云的
基本添加
增加一个Proxy Repository,id,name随便写,库地址就写http://maven.aliyun.com/nexus/content/groups/public
然后到Ordered Group Repositories这里把这个新加的库弄到左边。
再拖拽到Central库的上面,优先走阿里云的库,保存。
MAVEN XML的配置
Nexus 安装成功后,接下来需要修改 Maven 的配置文件(settings.xml),整合 Nexus。
找到 <servers> 标签,添加 Nexus 默认认证信息:
1
2
3
4
5
6
7
8
9
10
|
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
|
找到 <mirrors> 标签,添加镜像:
1
2
3
4
5
6
|
<mirror>
<!--This sends everything
else
to /
public
-->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http:
//localhost:8081/nexus/content/groups/public/</url>
</mirror>
|
找到 <profiles> 标签,添加仓库信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<profile>
<id>nexus</id>
<!--Enable snapshots
for
the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http:
//central</url>
<releases><enabled>
true
</enabled></releases>
<snapshots><enabled>
true
</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http:
//central</url>
<releases><enabled>
true
</enabled></releases>
<snapshots><enabled>
true
</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
|
激活仓库:
1
2
3
4
|
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
|
配置完成后保存,并重启 nexus 服务。
重启 nexus 服务 完成后,在命令行窗口进入一个使用 Maven 构建的项目,输入 mvn package clean 命令,清理完成后,登录 nexus 的 admin 账号可以看到 Public Repositories 下出现了一些 Jar 包。
添加第三方JAR包
选择3rd party 库下面 afifact upload标签
GAV Definition 选择 GAV Parameters
Auto Guess 默认 √
例
Group: com.solanexus
Artifact: springandswagger
Version: 1.0
Packaging: jar
下面select Artifact to upload 选择 要上传的jar包
选择好后,点击add Artifact会添加到下方的多行文本框。
最后点击 Upload Artifact 上传成功。