【Maven】---Nexus私服配置Setting和Pom
maven---nexus私服配置setting和pom
上一遍博客已经在linux服务器上,搭建好nexus私服了,博客地址:Linux搭建Nexus3.X私服
现在就需要配置setting.xml和pom.xml来使nexus作为maven的私服。setting.xml文件在conf下面,pom.xml是在你创建maven项目中的pom.xml中。
一、将jar发送到nexus私服务器
1、创建maven项目
创建一个最简单的maven项目,然后新建一个工具类,用来测试当把它打成jar包放到私服后,其它项目是否能够成功引用。

2、pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jincou</groupId>
<artifactId>xuxiaoxiao</artifactId>
<!--SNAPSHOT代表是快照版本-->
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>xuxiaoxiao</name>
<description>Demo project</description>
<distributionManagement>
<repository>
<!--id的名字可以任意取,但是在setting文件中的属性<server>的ID与这里一致-->
<id>releases</id>
<!--指向仓库类型为host(宿主仓库)的储存类型为Release的仓库-->
<url>http://47.96.4.110:8081/repository/java-release/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<!--指向仓库类型为host(宿主仓库)的储存类型为Snapshot的仓库-->
<url>http://47.96.4.110:8081/repository/java-snapshot/</url>
</snapshotRepository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
</project>
3、setting.xml配置
在这里只要配置登陆nexus的用户名密码,不然没有用户名和密码怎么能将jar包发送到私服呢。
<!--此处设置的用户名和密码都是nexus的登陆配置-->
<servers>
<server>
<id>releases</id> <!--对应pom.xml的id=releases的仓库-->
<username>xuxiaoxiao</username>
<password>xuxiaoxiao123</password>
</server>
<server>
<id>snapshots</id> <!--对应pom.xml中id=snapshots的仓库-->
<username>xuxiaoxiao</username>
<password>xuxiaoxiao123</password>
</server>
</servers>
注意: maven会判断版本后面是否带了-SNAPSHOT,如果带了就发布到snapshots仓库,否则发布到release仓库。这里我们可以在pom.xml文件中
执行命令:mvn deploy

发现部署到nexus私服成功,我们到私服查看下,因为这里的版本是带SNAPSHOT,所以会发布到snapshots仓库中。

说明已经成功将jar包发布到nexus私服中了。那么下一步是如何引用私服中的jar包了。
二、从nexus引用第三方jar包
让maven项目使用nexus作为远程仓库有两种方式,第一种是在项目的pom.xml中进行更改,让单个项目使用nexus仓库;另一种是通过修改maven的配置文件settings.xml进行更改,让所有项目都使用nexus仓库。我们这里采取第二种,只需要setting.xml就可以了。还有就是拉取jar的私服仓库地址只要写一个java-group就可以了,因为在创建这个组的时候,里面已经包含了其它三个仓库。
1、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">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<!--第一个nexus-xu要和下面的mirror中的id一致,代表拉取是也需要进行身份校验-->
<server>
<id>nexus-xu</id>
<username>xuxiaoxiao</username>
<password>xuxiaoxiao113</password>
</server>
<server>
<!--这两个前面讲过,是jar上传时候进行的验证,id对应的是pom中id属性的值-->
<id>releases</id>
<username>xuxiaoxiao</username>
<password>xuxiaoxiao113</password>
</server>
<server>
<id>snapshots</id>
<username>xuxiaoxiao</username>
<password>xuxiaoxiao113</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-xu</id>
<name>internal nexus repository</name>
<!--镜像采用配置好的组的地址-->
<url>http://47.96.44.110:8081/repository/java-group/</url>
<mirrorOf>!internal.repo,*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<!--ID用来确定该profile的唯一标识-->
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>nexus-pr</id>
<!-- 远程仓库列表 -->
<repositories>
<repository>
<id>nexus-xu</id>
<name>Nexus Central</name>
<!-- 虚拟的URL形式,指向镜像的URL-->
<url>http://47.96.44.110:8081/repository/java-group/</url>
<layout>default</layout>
<!-- 表示可以从这个仓库下载releases版本的构件-->
<releases>
<enabled>true</enabled>
</releases>
<!-- 表示可以从这个仓库下载snapshot版本的构件 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件仓库列表 -->
<pluginRepositories>
<pluginRepository>
<id>nexus-xu</id>
<name>Nexus Central</name>
<url>http://47.96.44.110:8081/repository/java-group/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--需要激活 <profile>中的ID才生效-->
<activeProfile>nexus-pr</activeProfile>
<activeProfile>jdk-1.8</activeProfile>
</activeProfiles>
</settings>
2、验证
(1)新建项目添加pom依赖
<dependencies>
<dependency>
<groupId>com.jincou</groupId>
<artifactId>xuxiaoxiao</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
(2)看是否拉取到私服的jar包

并没有报错,表拉取成功
(3)写测试类

引用成功
(4)看后台输出

输出成功
从这里将jar包发送到私服和从私服拉取jar就成功了。
参考
1、maven发布jar包到nexus
2、让Maven项目使用Nexus作为远程仓库的settings.xml配置
3、Maven 全局配置文件settings.xml详解
如果一个人充满快乐,正面的思想,那么好的人事物就会和他共鸣,而且被他吸引过来。同样,一个人老带悲伤,倒霉的事情也会跟过来。
——在自己心情低落的时候,告诫自己不要把负能量带给别人。(大校2)
【Maven】---Nexus私服配置Setting和Pom的更多相关文章
- Maven私服配置Setting和Pom文件
上一遍博客已经在linux服务器上,搭建好nexus私服了 现在就需要配置setting.xml和pom.xml来使nexus作为maven的私服.setting.xml文件在conf下面,pom.x ...
- 基于nexus私服配置项目pom.xml和maven settings.xml文件
备注:搭建nexus私服请参考上一篇文章基于Docker搭建Maven私服Nexus,Nexus详解 一:将jar发送到nexus私服务器 1.pom.xml文件添加配置 pom.xml文件中的这个版 ...
- Maven基础配置--nexus私服配置
登录nexus私服后台,按照下图1-3的顺序进行添加仓库: 其中步骤3有三种仓库类型(Type)进行选择 1. Hosted Repository:本地仓库,在私服服务器上存放用户自行上传的jar包: ...
- Maven之私服配置
一.配置从私服下载 从私服下载主要是将 central 库的下载地址从https://repo1.maven.org/maven2/修改为私服地址,比如http://localhost:8081/re ...
- maven nexus 私服搭建 Windows版
准备工作 已安装jdk,并配置好了环境变量 已安装maven,并配置好了环境变量 下载Nexus Repository OSS:https://www.sonatype.com/download-os ...
- maven nexus私服搭建,特别痛苦!!
一.下载nexu,配置环境 参考我的文章:http://www.cnblogs.com/quanyongan/archive/2013/04/24/3037589.html 二.解压并准备Nexus安 ...
- maven仓库私服配置
私服访问地址:[[http://192.168.1.252:9080/nexus/content/groups/public/ 地址]] 1. 打开eclipse/myeclipse的maven插件: ...
- maven nexus私服搭建
1. 下载 wget http://download.sonatype.com/nexus/oss/nexus-2.12.0-01-bundle.tar.gz 2. 解压 tar zxvf nexus ...
- maven nexus 私服的搭建学习
之前对maven有过初步的了解与认识,自己也创建过项目使用其来管理,但都是非常粗浅的操作,今天在高人的指点下,也学着在自己的电脑上搭建一个maven私服,虽然技术难度也不高,但为了更深层次的提高,这些 ...
随机推荐
- 使用Tornado异步接入第三方(支付宝)支付
目前国内比较流行的第三方支付主要有支付宝和微信支付,博主最近研究了下如何用Python接入支付宝支付,这里我以Tornado作为web框架,接入支付宝构造支付接口. 使用Tornado异步接入支付宝支 ...
- Python3-Cookbook总结 - 第二章:字符串和文本
第二章:字符串和文本 几乎所有有用的程序都会涉及到某些文本处理,不管是解析数据还是产生输出. 这一章将重点关注文本的操作处理,比如提取字符串,搜索,替换以及解析等. 大部分的问题都能简单的调用字符串的 ...
- redux+saga+reducer
saga.js这个文件里面的函数实际没有在其他jsx中引用吧?这个文件的作用就是把异步数据拿到,放进reducer,如果jsx想取,需要结合connect来取数据.
- Dancing Links 学习笔记
Dancing Links 本周的AI引论作业布置了一道数独 加了奇怪剪枝仍然TLE的Candy?不得不去学了dlx dlxnb! Exact cover 设全集X,X的若干子集的集合为S.精确覆盖是 ...
- lua 文件编译相关工具
-- 编译一个代码文件 -- loadfile (lua_State *L, const char *filename); -- 将一个文件加载为lua代码块,仅编译不执行,返回值为编译后的 -- 代 ...
- Web端常见问题总结
1.ES6箭头函数和普通函数的区别(至少3点) (1)箭头函数的this永远指向其上下文的 this,任何方法都改变不了其指向,如call(), bind(), apply(),普通函数的this指向 ...
- redis + cookies 实现持久登入
通过登入把用户信息和token加载到redis中去, 将token和部分用户信息存储在cookie中, 下次登入时 判断cookie的token在redis中是否存在, 存在就把用户信息加载出来自动登 ...
- 大数据计算框架Hadoop, Spark和MPI
转自:https://www.cnblogs.com/reed/p/7730338.html 今天做题,其中一道是 请简要描述一下Hadoop, Spark, MPI三种计算框架的特点以及分别适用于什 ...
- position 几个属性的作用
//定位一般都会配合left 和 top 一起使用; //静态定位 : 元素默认位置; 不脱标 不常用position:static; //相对定位 : 相对于元素本身之前的位置进行定位;不脱标pos ...
- python从入门到实践-8章函数
#!/user/bin/env python# -*- coding:utf-8 -*- # 给形参指定默认值时,等号两边不要有空格 def function_name("parameter ...