原文出处http://www.yund.tech/zdetail.html?type=1&id=3688b5fa1f7d7df8b183ad8c9503546d

作者:jstarseven


上一遍博客已经在linux服务器上,搭建好nexus私服了

现在就需要配置setting.xmlpom.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就成功了。


-END-

Maven私服配置Setting和Pom文件的更多相关文章

  1. 【Maven】---Nexus私服配置Setting和Pom

    maven---nexus私服配置setting和pom 上一遍博客已经在linux服务器上,搭建好nexus私服了,博客地址:Linux搭建Nexus3.X私服 现在就需要配置setting.xml ...

  2. 使用阿里云的maven私服的setting.xml, 提高maven项目jar下载速度

    下载: http://files.cnblogs.com/files/007sx/settings.zip 然后替换自己原本maven的配置文件. 如下载失败,可内容替换: <?xml vers ...

  3. Maven 私服配置 转

    1.配置Nexus为maven的私服 第一种方式:在项目的POM中如下配置 <repositories>     <repository>         <id> ...

  4. maven私服配置

    1.maven私服setting.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <setting ...

  5. Maven学习详解(13)——Maven常用命令大全与pom文件讲解

    一.Maven常用命令 1.1.Maven 参数 -D 传入属性参数  -P 使用pom中指定的配置  -e 显示maven运行出错的信息  -o 离线执行命令,即不去远程仓库更新包  -X 显示ma ...

  6. maven常用配置setting.xml详解

    参考文章: https://www.cnblogs.com/hwaggLee/p/4579418.html 1.<localRepository/> 该值maven本地仓库的路径 < ...

  7. Maven -------------- Eclipse 安装maven ,配置setting文件

    1.设置maven路径 Window->Preferences->Maven->Installations-> 选择maven的路径,如果原来有低版本的建议删除 选择好后点击f ...

  8. Maven 打jar包,pom文件配置

    以下是pom.xml文件的相关配置. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...

  9. maven 私服的setting.xml配置

    <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns="http://m ...

随机推荐

  1. WEB API 有效的Action定义

    不能有特殊名称(例如属性访问器和运算符的重载方法) 的某些编译器以特殊方式处理的成员.可使用MethodInfo.IsSpecialName判断. 不能标记为[NonAction] 所在的类必须是Ap ...

  2. Mark: 实现个toy版的脚手架(RPC)

    p.s.  这些小toy的规模都在几百~上千行代码量,但足以反映一个tool的核心思想. 包括: 一些中间件(消息队列.Netty) Spring的IoC容器:(自动依赖注入) —— 就是利用Java ...

  3. Centos中编辑php扩展库

    今天需要在Centos中编译Exif库以便获取图片的exif信息,可在Linux中从来没有编译过扩展库呀,只好查资料了.发现是用phpize这个东东来编译扩展. 首先执行了下 php -i | gre ...

  4. Windows Server2008R2,ServerWin2012 R2设置自动登录注册表配置

    serverWin2008 R2 2012自动登录一般是通过control userpasswords2 命令修改,其实注册表修改更简单.复制以下保存为xx.reg文件导入即可即可. Windows ...

  5. js中面向对象(创建对象的几种方式)

    1.面向对象编程(OOP)的特点: 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有的对象下继承出新的对象 多态:多对象的不同形态 注:本文引用于 http://www.cnblogs. ...

  6. 使用<label>标签修改input[type="checkbox"]的样式

    因为<label>的特性有两点 : ①不呈现任何效果, ②用户点击该标签, 浏览器能自动将焦点转移到相关的表单控件上. <form> <input type=" ...

  7. 高德地图的JSAPI学习笔记【一】

    高德地图的项目要做 学习笔记记录下来 一.注册账号并申请Key  二.准备页面写好 1.在页面添加 JS API 的入口脚本标签,并将其中「您申请的key值」替换为您刚刚申请的 key: <sc ...

  8. App过大

    最近开发中遇到一个报错信息 如下 Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex li ...

  9. Html引入百度富文本编辑器ueditor及自定义工具栏

    在日常工作用,肯定有用到富文本编辑器的时候,富文本编辑器功能强大使用方便,我用的是百度富文本编辑器,首先需要下载好百度编辑器的demo, 然后创建ueditor.html文件,引入百度编辑器,然后在h ...

  10. Angular----样式

    本篇根据Angular官网提供的例子,对Angular涉及到的样式绑定进行说明. 一.提供的CSS样式 .red{ color:red; } .green{ color: green; } .yell ...