maven setting 配置仓库,pom.xml中repository不起作用

问题描述

最近做java项目,需要使用公司自己搭建的maven仓库,但是有些包公司的仓库中没有,导致下载失败。

项目环境

jdk:1.8

maven:3.5

问题原因分析

maven的setting文件配置信息如下:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
    <localRepository>/data/repository</localRepository>
    <servers>
        <server>
            <id>releases</id>
            <username>123</username>
            <password>123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>123</username>
            <password>123</password>
        </server>
    </servers>
    <mirrors>
        <!--注意标红的部分-->
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://server.dev.****.com:8000/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>

pom.xml中的配置:

<repositories>
			<repository>
			<id>aliyun-repos</id>
			<url>https://maven.aliyun.com/repository/public</url>
			<releases><enabled>true</enabled></releases>
			<snapshots><enabled>false</enabled></snapshots>
		</repository>
        <repository>
		    <id>sonatype-repos-s</id>
			<name>Sonatype Repository</name>
			<url>https://oss.sonatype.org/content/repositories/snapshots</url>
			<releases><enabled>false</enabled><updatePolicy>always</updatePolicy></releases>
			<snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
		</repository>
	</repositories>

  

我需要下载的包的仓库地址在pom文件中配置了,就是 https://oss.sonatype.org/content/repositories/snapshots,这个仓库,

但是为什么下载的时候没有起作用呢?问题就出在setting中如下部分:

<mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://server.dev.****.com:8081/nexus/content/groups/public/</url>
</mirror> 

mirrorof标签,这个标签如果设置为*,就说明整个工程只能使用settings中配置的地址,这个就是问题的根源。

解决办法

  在settings文件的mirrorof标签中内容改成(!sonatype-repos-s,*),括号里面的内容,不包括括号,这样做的意思是,!sonatype-repos-s意思是把sonatype-repos-s这个仓库排除在外,依然把公司的仓库作为唯一仓库,这样就可以使用settings文件中配置的仓库和pom.xml配置的仓库都生效。

-------------------------------------------------------------分割线---------------------------------------------------------------

番外话:上面的问题产生的根本原因是,我们平时做项目时一般都是复制粘贴,根本不知道有些配置项什么意思,出了问题就百度,但是有时百度查不到时,还是要老老实实的从原理入手。

原文地址:https://www.cnblogs.com/gunduzi/p/11715726.html

时间: 2024-08-09 23:43:56

maven setting 配置仓库,pom.xml中repository不起作用的相关文章

在 eclipse中 创建 web 版的 maven 工程以及 进一步了解 pom.xml 中 scope 的相关配置设置问题

1.在 eclipse中 创建 web 版的 maven 工程: a.和 创建 java 版的 maven 工程一样,先选中一个简单的工程(跳过经典模式),后填写坐标(不了解的看先前的博文),在打包方式中选择 war 包,后点击 finish. b.可以看到,在新建 的 javaproject03 的 项目中,只有 webapp目录,而实际的内容并没有.这里我们在每次新建时都要做设置.设置如下: 注:鼠标停在所建的项目上,点击右键进入 properties --> Project Facets

(转)如何在maven的pom.xml中添加本地jar包

1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将maven本地仓库中的jar包添加到项目中,直接打开4 xx.pom文件,将改jar包的相关依赖复制pom.xml文件中即可. 2 将本地jar包添加到本地仓库 2.1 添加jar到本地仓库 原则上Maven的设计是不需要这么做的,因为pom.xml中依赖的jar包会自动实现从中央仓库下载到本地仓库

pom.xml中添加远程仓库

maven的pom.xml中添加远程仓库 <repositories> <repository> <id>mvnrepository</id> <name>mvnrepository</name> <url>http://www.mvnrepository.com/</url> <layout>default</layout> <releases> <enabled&g

maven的pom.xml中出现Multiple annotations found at this line:错误

一般这个错误出现在pom.xml的第一行,出错信息如下: Multiple annotations found at this line: - Missing artifact stax:stax-api:jar:1.0.1 - ArtifactTransferException: Failure to transfer stax:stax-api:jar:1.0.1 from http://dist.codehaus.org/ was cached in the local repositor

Maven pom.xml中的元素modules、parent、properties以及import

前言 项目中用到了maven,而且用到的内容不像利用maven/eclipse搭建ssm(spring+spring mvc+mybatis)用的那么简单:maven的核心是pom.xml,那么我就它来谈谈那些不同的地方: 给我印象最深的就是如下四个元素:modules.parent.properties.import. modules 从字面意思来说,module就是模块,而pom.xml中的modules也正是这个意思,用来管理同个项目中的各个模块:如果maven用的比较简单,或者说项目的模

log4j的1.2.15版本,在pom.xml中的顶层project报错错误: Failure to transfer javax.jms:jms:jar:1.1 from https://maven-repository.dev.java.net/nonav/repository......

在动态网站工程中,添加了Pom依赖,当添加log4j的1.2.15版本依赖时,在pom.xml中的顶层project报错错误: Failure to transfer javax.jms:jms:jar:1.1 from https://maven-repository.dev.java.net/nonav/repository......,如下图 这是因为 https://maven-repository.dev.java.net/nonav/repository 这个域名已经无法解析了. 而

eclipse中基于maven构建的web项目pom.xml中指定的jar包无法发布到tomcat中

eclipse运行maven web项目报错: 信息: Starting Servlet Engine: Apache Tomcat/7.0.57 一月 07, 2015 11:50:44 下午 org.apache.catalina.core.ContainerBase startInternal 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catal

在pom.xml中设置maven工程编码

在pom.xml中添加属性project.build.sourceEncoding就可以设置工程的编码 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> 版权声明:本文为博主原创文章,未经博主允许不得转载.

在pom.xml中使用distributionManagement将项目打包上传到nexus私服

本文介绍 如何在pom.xml中使用distributionManagement将项目打包上传到nexus私服 1.pom.xml文件添加distributionManagement节点 <!-- 使用分发管理将本项目打成jar包,直接上传到指定服务器 --> <distributionManagement> <!--正式版本--> <repository> <!-- nexus服务器中用户名:在settings.xml中<server>的