本文共 2511 字,大约阅读时间需要 8 分钟。
Nexus私服原理图
下载地址是。默认端口8081。
Nexus常用功能(这里介绍):
1、指定私服的中央地址
2、将自己的Maven项目指定到私服地址
3、从私服下载中央库的项目索引
4、从私服仓库下载依赖组件
5、将第三方项目jar上传到私服供其他项目组使用。
如何使用:
下载最新版nexus,目前是2.12,解压缩后,进入nexus-2.12.0-01\bin\jsw\(根据你的os系统, 选择相应的文件夹,我的是windows64位,所以进入如下界面:
开启Nexus服务后访问url地址http://localhost:8081/nexus/(推荐使用自己的ip地址),之后登录系统,用户名密码分别是:admin/admin123.
点击左侧菜单栏的按钮。
hosted 类型的仓库,内部项目的发布仓库
releases 内部的模块中release模块的发布仓库
snapshots 发布内部的SNAPSHOT模块的仓库
3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
proxy 类型的仓库,从远程中央仓库中寻找数据的仓库
group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库
下载Maven项目索引,项目索引是为了使用者能够在私服站点查找开发所需的jar依赖,选择central,在底下的configuration里选择自动下载。
保存后后台会运行一个任务,点击菜单栏的选项即可看到有个任务在RUNNING。
下载完成后,Maven索引就可以使用了,在搜索栏输入要搜索的项,就可以查到相关的信息。例如struts
就可以检索出它的相关信息,复制右下角的pom依赖,就知道怎么配置依赖信息。
如何使用
1、单独一个项目使用这个私服仓库,先在项目pom中配置相关私服信息:
<repositories>
<repository> <id>nexus</id> <name>nexus</name> <url>http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>nexus</name> <url>http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>这样只有本项目在私服下载组件,这个Maven项目构建的时候会从私服下载相关依赖。当然这个配置仅仅是在此项目中生效,对于其他项目还是不起作用。
2、如果相对Maven的其他项目也生效的话。需要修改全局的settings.xml文件。
<?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"> <localRepository>D:\00Coding\apache-maven\public_repo</localRepository> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> </mirrors> <profiles> <profile> <repositories> <repository> <id>central</id> <name>central</name> <url>http://localhost:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>central</activeProfile> </activeProfiles> </settings>之后所有本机的Maven项目就在私服下载组件。(这样比较好)
宿主库——3rd party
假如我们下载了Oracle的驱动程序jar包想给其他项目组使用,就需要上传该jar包。选中宿主库——3rd party,之后选择Artifact Upload上传至宿主空间。
最后点击上传。先写到这里,要码代码了