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

本文介绍如何在CentOS环境下使用Sonatype Nexus搭建Maven私有库,并进行详细的配置步骤说明,包括Nexus服务的安装、配置、启动及权限设置等,最后讲解如何在本地Maven项目中配置私有库。

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

SonatypeNexus + Maven

环境:CentOS6.6FinalJDK7Sonatype NexusMaven

IP:192.168.4.221

root用户操作

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

1、下载最新版Nexus(本教程使用的是:nexus-2.11.2-03-bundle.tar.gz,下载地址:http://www.sonatype.org/nexus/go/

#wgethttps://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

2、解压

# mkdirnexus

# tar -zxvfnexus-2.11.2-03-bundle.tar.gz -C nexus

# cd nexus

# ls

nexus-2.11.2-03 sonatype-work

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

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

# cdnexus-2.11.2-03

# ls

bin conf lib  LICENSE.txt  logs nexus NOTICE.txt  tmp

查看目录结构,jetty运行

# cd conf

# vinexus.properties

# Jettysection

application-port=8081

application-host=0.0.0.0

nexus-webapp=${bundleBasedir}/nexus

nexus-webapp-context-path=/nexus

# Nexussection

nexus-work=${bundleBasedir}/../sonatype-work/nexus

runtime=${bundleBasedir}/nexus/WEB-INF

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

# vi /root/nexus/nexus-2.11.2-03/bin/nexus

#RUN_AS_USER=

改为:

RUN_AS_USER=root

5、防火墙中打开8081端口

# vi/etc/sysconfig/iptables

添加:

-A INPUT -mstate --state NEW -m tcp -p tcp --dport 8081 -jACCEPT

保存后重启防火墙

# serviceiptables restart

6、启动nexus

#/root/nexus/nexus-2.11.2-03/bin/nexus start

****************************************

WARNING -NOTRECOMMENDED TO RUN AS ROOT

****************************************

StartingNexus OSS...

StartedNexus OSS.

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


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

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

Nexus配置(登录后)

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

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

用户修改密码

1、仓库类型

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

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

proxy代理仓库:代理公共的远程仓库;

virtual虚拟仓库:用于适配Maven1

一般用到的仓库种类是hostedproxy

Hosted仓库常用类型说明:

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

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

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

如果构建的Maven项目本地仓库没有对应的依赖包,那么就会去Nexus私服去下载,

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

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

4Maven本地库的安装与配置

环境变量、setting.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>E:/apache-maven-3.1.0/.m2/repository</localRepository>
	<interactiveMode>true</interactiveMode>
    <offline>false</offline>
    <pluginGroups>
        <pluginGroup>org.mortbay.jetty</pluginGroup>
        <pluginGroup>org.jenkins-ci.tools</pluginGroup>
    </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.4.221: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.4.221: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>

5MyEclipse中的Maven配置


6、项目的构建与发布演示

修改pom.xml中的私有库地址

7、上传第三方包操作演示

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值