Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

时间:2023-03-09 17:33:11
Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

环境:CentOS 7.0 Final、JDK8、Sonatype Nexus、Maven

虚拟机模拟IP:192.168.16.167

备注:root权限用户操作

前提:已安装 JDK8 并配置好了环境变量

1、下载最新版 Nexus,下载地址: http://www.sonatype.org/nexus/go/

# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.203-bundle.tar.gz 

2、解压

# mkdir nexus
# tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C nexus
# cd nexus
# ls
    nexus-2.11.2-03 sonatype-work
备注:(一个 nexus 服务,一个私有库目录) 

3、编辑 Nexus 的 nexus.properties 文件,配置端口和 work 目录信息(保留默认即可)

# cd nexus-2.11.2-03
# ls
bin conf lib LICENSE.txt logs nexus NOTICE.txt tmp

备注:查看目录结构后,Jetty 运行

# cd conf
# vim nexus.properties
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus # Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

4、编辑 nexus 脚本, 配置 RUN_AS_USER 参数

# vim  /root/nexus/nexus-2.11.2-03/bin/nexus
#RUN_AS_USER=
改为:
RUN_AS_USER=root

5、防火墙中打开 8081 端口

# vim /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
保存后重启防火墙
# service iptables restart

6、启动 nexus

# /root/nexus/nexus-2.11.2-03/bin/nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.

7、浏览器中打开:http://192.168.16.167:8081/nexus/

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

8、登录,默认用户名 admin,默认密码 admin123:

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

Nexus 配置(登录后)

1、菜单 Administration/Server 配置邮箱服务地址(如果忘记密码,可以通过该邮箱找回密码)
Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

  给用户配置邮箱地址,方便忘记密码时找回:

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

  用户修改密码

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

2、仓库类型

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

求仓库组即可请求到仓库组管理的多个仓库; hosted 宿主仓库:主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件) 以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动) proxy 代理仓库:代理公共的远程仓库; virtual 虚拟仓库:用于适配 Maven 1; 一般用到的仓库种类是 hosted、proxy

Hosted 仓库常用类型说明: releases 内部的模块中 release 模块的发布仓库 snapshots 发布内部的 SNAPSHOT 模块的仓库 3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

如果构建的 Maven 项目本地仓库没有对应的依赖包,那么就会去 Nexus 私服去下载, 如果Nexus私服也没有此依赖包,就回去远程*仓库下载依赖,这些*仓库就是proxy。 Nexus 私服下载成功后再下载至本地 Maven 库供项目引用。

3、设置 proxy 代理仓库(Apache Snapshots/Central/Codehaus Snapshots)准许远程下载, 如:

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

4、Maven 本地库的安装与配置(请看参考http://www.cnblogs.com/libingbin/p/6104588.html )

  环境变量、setting.xml 、修改 pom.xml 中的私有库地址

<!-- Start -->

获知及时信息,请关注我的个人微信订阅号:0与1的那点事

Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

<!-- End -->

本文为博主原创文章,转载请注明出处!

http://www.cnblogs.com/libingbin/

感谢您的阅读。