Maven私服--Nexus的本地xml配置

本文详细介绍了如何在Maven中配置私服,包括setting.xml文件中私服镜像源、部署凭证的设置方法,以及pom.xml文件中部署仓库的配置方式。

一、setting.xml配置:

(1)将下载源改成私服:

 <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

(2)如果要deploy到私服,要配置:

<servers>
	<server>
		<id>nexus-releases</id>
		<username>XXXXXXX</username>
		<password>******</password>
	</server>
	<server>
		<id>nexus-snapshots</id>
		<username>XXXXXXX</username>
		<password>******</password>
	</server>
  </servers>
二、pom.xml配置:

(1)要deploy到私服,要配置:

<distributionManagement>
		<repository>
			<id>nexus-releases</id>
			<name>Nexus Releases Repository</name>
			<url>http://localhost:8081/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus-snapshots</id>
			<name>Nexus Snapshots Repository</name>
			<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>


Maven 配置中无法下载 `maven-metadata-*.xml` 文件可能由多种原因导致,以下是一些常见的解决办法: ### 网络问题 若网络连接不稳定或存在限制,会影响文件下载。可检查网络连接,确保网络正常,也可尝试切换网络环境。若使用代理,需检查代理配置是否正确,可查看 `~/.m2/settings.xml` 文件中的 `<proxies>` 部分,确保代理信息无误。例如: ```xml <proxies> <proxy> <id>myproxy</id> <active>true</active> <protocol>http</protocol> <host>proxy.example.com</host> <port>8080</port> <username>proxyuser</username> <password>proxypass</password> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies> ``` ### 仓库配置问题 检查 `settings.xml` 文件中 `<repositories>` 和 `<pluginRepositories>` 部分的仓库配置是否正确,确保仓库的 URL 可访问。例如: ```xml <repositories> <repository> <id>central</id> <name>Maven Central</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> ``` ### 本地仓库问题 有时候本地仓库文件损坏会导致无法下载元数据文件,可尝试删除本地仓库中对应依赖的文件夹,让 Maven 重新下载。本地仓库默认路径为 `~/.m2/repository`。 ### 服务器问题 Maven 服务器可能出现故障或维护,可检查 Maven 官方仓库或私服的状态,确认服务器是否正常。 ### 代理配置问题 若使用 Gradle 构建项目,可检查 `C:\*.gradle` 下的 `gradle.properties` 文件,是否存在多余的代理配置,若有则删除[^3]。 ### 版本比对问题 Maven 在构建后会从 Maven 服务器下载最新的 `maven-metadata.xml` 文件,与本地仓库中 `jar` 包文件夹下的 `maven-metadata-local.xml` 做比较,根据 `lastUpdated` 时间戳值决定使用哪个文件。若本地文件时间戳值大,则使用本地 `jar` 包,所以要确保本地有想用的 `jar` 包[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值