一、Windows 环境下的安装与配置
1.1、安装前提
JDK:1.7 及以上版本,并配置相关环境变量。
1.2、Nexus 安装
首先,我们需要从官网上下载 Nexus 安装包。
Nexus2.14 下载地址:https://www.sonatype.com/download-oss-sonatype
下载 nexus-2.14.8-01-bundle.zip 后解压至某一目录,路径
中最好不要带中文名称及空格,解压后目录清单如下:
解压后,进入安装目录下 nexus-2.14.8-01\bin\目录:
image.png
使用管理员权限打开 cmd,在当前文件夹下执行以下命令安装服务:nexus install
image.png
1.3、Nexus 启动配置
有两种启动方式:
1.使用管理员权限打开 cmd 在当前文件夹下执行以下命令:nexus start
image.png
2.右键电脑-->管理-->服务-->nexus-->启动。(可设置为手动启动。)
Nexus的默认地址为:http://localhost:8081/nexus/,访问后显示如
下内容,则说明启动成功:
二、Linux 环境下的安装与配置
2.1、安装前提
JDK:1.7 及以上版本,并配置相关环境变量。
2.2、Nexus 安装
首先,我们需要从官网上下载 Nexus 安装包。
Nexus2.14 下载地址:https://www.sonatype.com/download-oss-sonatype
下载 nexus-2.14.1-01-bundle.tar.gz 并解压即可:
#cd /home/tools
#tar zxvf nexus-2.4.0-09-bundle.tar.gz
#mv nexus-2.4.0-09 /usr/local/nexus
2.3、Nexus 启动配置
使用命令启动:
#cd /usr/local/nexus/bin
#./nexus start
#./nexus stop
默认地址为:http://localhost:8081/nexus/,访问后显示如
下内容,则说明启动成功:
三、普元EOS仓库部署
3.1、部署前提
用户已经安装了 Nexus2.14,并获得了普元离线编译包storage-eosplatform76.zip。
3.2、登录
点击右上角 Log in,默认账户密码为:admin/admin123。
image.png
点击左侧 Repositories,即可看见系统自带的一些仓库:
image.png
Nexus 的仓库分为 4 类:
1.hosted 宿主仓库:本质上就是本地仓库。
2.proxy 代理仓库:代理远程仓库,配置远程仓库地址后,可以从远程仓库获取 jar 包。
3.virtual 虚拟仓库:用于适配 Maven 1 格式,基本不用。
4.group 仓库组:通过仓库组的概念统一管理多个仓库,在项目中请求仓库组即可请求组中的所有仓库。
3.3、新建仓库
由上仓库分类,我们可以新建一个 hosted 仓库以供使用。
点击 Add,选择 hosted 仓库:
image.png
填入 ID 和 name,然后点击 Save进行保存:
image.png
3.4、添加离线 jar 包
进入安装目录下\sonatype-work\nexus\storage\,这里保存的是 Nexus 所有仓库的信息和 jar 包,进入我们新建的仓库 primeton_maven:
image.png
然后将 storage-eosplatform76.zip 解 压 到 安 装 目 录 下\sonatype-work\nexus\storage\ primeton_maven\文件夹下:
image.png
在浏览器中,选择新建的仓库,点击 Browse Storage,并点击刷新,可以看到所需 jar 包已经导入:
image.png
3.5、配置 maven setting 文件
打开 maven 安装目录,在 conf 文件夹下 setting.xml 文件,进行如下配置:
示例一:
<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>E:\test</localRepository>
<profiles>
<profile>
<id>myNexus</id>
<repositories>
<repository>
<id>test</id>
<url>http://localhost:8081/nexus/content/repositories/test/
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>test</id>
<url>http://localhost:8081/nexus/content/repositories/test/
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>myNexus</activeProfile>
</activeProfiles>
</settings>
示例二
<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>E:\Maven_Repository</localRepository>
<profiles>
<profile>
<id>primeton-repositorys</id>
<repositories>
<repository>
<id>primeton_maven</id>
<url>http://localhost:8081/nexus/content/repositories/primeton_maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>primeton-public-repository</id>
<url>http://localhost:8081/nexus/content/groups/primeton_public_repositories/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>primeton-p2-repository</id>
<url>http://localhost:8081/nexus/content/repositories/primeton_p2_eclipse_repository/.meta/p2</url>
<layout>p2</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>primeton-release-p2-repository</id>
<url>http://localhost:8081/nexus/content/repositories/primeton_products_release/.meta/p2</url>
<layout>p2</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>primeton_maven</id>
<url>http://localhost:8081/nexus/content/repositories/primeton_maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>primeton-repositorys</activeProfile>
</activeProfiles>
</settings>
注意:
1.localRepository 为本地 maven 存储库地址。
2.profile 下 ID 与 activeProfiles 中对应。
3.repository 和 pluginRepository 中,ID 与我们新建的仓库 ID对应,url 与 Nexus 生成的仓库地址对应。
配置完成后 maven 在获取 jar 包时,就会从新建仓库中获取。
网友评论