linux学习:持续集成篇–Maven私有库和本地库的安装与配置-03推

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

maven私服器Sonatype Nexus的安装与配置

1、安装

1.1下载 Nexus(这里使用的是:nexus-2.11.2-03-bundle.tar.gz)

http://www.sonatype.org/nexus/go/

1.2解压:因为解压后有两个文件夹,所以这里新建了一个nexus文件夹

[root@localhostopt]#mkdirnexus[root@localhostopt]#tar-zxvf/opt/tar/nexus-2.11.2-03-bundle.tar.gz-C/opt/nexus/[root@localhostopt]#cdnexus/[root@localhostnexus]#lsnexus-2.11.2-03sonatype-work[root@localhostnexus]#

(一个 nexus 服务,一个私有库目录)

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

[root@localhost conf]# cat nexus.properties

#Jettysectionapplication-port=8081application-host=0.0.0.0nexus-webapp=${bundleBasedir}/nexusnexus-webapp-context-path=/nexus#Nexussectionnexus-work=${bundleBasedir}/../sonatype-work/nexusruntime=${bundleBasedir}/nexus/WEB-INF

1.4编辑 nexus 脚本

vi/opt/nexus/nexus-2.11.2-03/bin/nexus#改成rootRUN_AS_USER=root

1.5启动

/opt/nexus/nexus-2.11.2-03/bin/nexusstart

1.6访问:http://192.168.175.9:8081/nexus

1.7登录,默认用户名 admin,默认密码 admin123

到此,Nexus 已安装完成,接下来是 Nexus 的配置

2、配置(登录后)

2.1 菜单 Administration/Server 配置邮箱服务地址(如果忘记密码,可以通过该邮箱找回密码)

测试邮箱:

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

2.2 修改密码

2.3 仓库

group仓库组:

Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库

hosted宿主仓库:

主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件)以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)

proxy代理仓库:

代理公共的远程仓库;

virtual虚拟仓库:

用于适配 Maven 1;

一般用到的仓库种类是 hosted、proxy。

Hosted仓库常用类型说明:

releases:内部的模块中 release 模块的发布仓库

snapshots:发布内部的 SNAPSHOT 模块的仓库

3rd party:第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

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

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

注意:这里3个proxy都设置

setting.xml配置:

 ?xmlversion="1.0"encoding="UTF-8"?  settingsxmlns="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.0http://maven.apache.org/xsd/settings-1.0.0.xsd"  localRepository G:\workspace\maven_space /localRepository  interactiveMode true /interactiveMode  offline false /offline  pluginGroups  /pluginGroups  !--配置权限,使用默认用户--  servers  server  id nexus-releases /id  username deployment /username  password deployment123 /password  /server  server  id nexus-snapshots /id  username deployment /username  password deployment123 /password  /server  /servers  mirrors  /mirrors  profiles  profile  id edu /id  activation  activeByDefault false /activeByDefault  jdk 1.6 /jdk  /activation  repositories  !--私有库地址 repository  id nexus /id  url http://192.168.175.9:8081/nexus/content/groups/public/ /url  releases  enabled true /enabled  /releases  snapshots  enabled true /enabled  /snapshots  /repository  /repositories  pluginRepositories  !--插件库地址--  pluginRepository  id nexus /id  url http://192.168.175.9:8081/nexus/content/groups/public/ /url  releases  enabled true /enabled  /releases  snapshots  enabled true /enabled   /snapshots  /pluginRepository  /pluginRepositories  /profile  /profiles  !--激活profile--  activeProfiles  activeProfile edu /activeProfile  /activeProfiles  /settings 

项目的构建与发布:pom.xml

 distributionManagement  repository  id nexus-releases /id  name NexusReleaseRepository /name  url http://192.168.175.9:8081/nexus/content/repositories/releases/ /url  /repository  snapshotRepository  id nexus-snapshots /id  name NexusSnapshotRepository /name  url http://192.168.175.9:8081/nexus/content/repositories/snapshots/ /url  /snapshotRepository  /distributionManagement 

发布到私有库:

pom: version 1.0-SNAPSHOT /version

pom: version 1.0-RELEASES /version

4、上传第三方jar,如:demo.jar

配置其开机启动

1、负责nexus到/etc/init.d下

cp/opt/nexus/nexus-2.11.2-03/bin/nexus/etc/init.d/nexus

2、修改nexus

[root@localhost~]#vi/etc/init.d/nexusNEXUS_HOME="/opt/nexus/nexus-2.11.2-03/"

3、修改wrapper.conf

[root@localhost~]#vi/opt/nexus/nexus-2.11.2-03/bin/jsw/conf/wrapper.confwrapper.java.command=/home/jdk1.7.0_71/bin/java

4、添加脚本的可执行权限

chmod755/etc/init.d/nexus

5、添加为系统服务

chkconfig--addnexus

带着感恩的心启程,学会爱,爱父母,爱自己,爱朋友,爱他人。

linux学习:持续集成篇–Maven私有库和本地库的安装与配置-03推

相关文章:

你感兴趣的文章:

标签云: