You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven构建报错:maven-war-plugin:3.1.0无法从中央仓库获取

解决Eclipse Luna中Maven构建maven-war-plugin连接超时问题

你遇到的问题是Maven无法从中央仓库拉取maven-war-plugin:3.1.0的POM文件,且本地缓存了失败状态导致后续无法自动重试。结合你已经尝试的操作,这里提供几个针对性的解决方案:


问题回顾

你的Spring Boot项目POM内容如下:

<?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.example</groupId> 
<artifactId>student-services</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<name>student-services</name> 
<description>Demo project for Spring Boot</description> 
<parent> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-parent</artifactId> 
<version>2.0.1.RELEASE</version> 
<relativePath /> <!-- lookup parent from repository --> 
</parent> 
<properties> 
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
<java.version>1.8</java.version> 
<docker.image.prefix>hello-howtodoinjava</docker.image.prefix> 
</properties> 
<dependencies> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter</artifactId> 
</dependency> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-test</artifactId> 
<scope>test</scope> 
</dependency> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
</dependencies> 
<build> 
<plugins> 
<plugin> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-maven-plugin</artifactId> 
</plugin> 
<plugin> 
<groupId>com.spotify</groupId> 
<artifactId>dockerfile-maven-plugin</artifactId> 
<version>1.3.4</version> 
<configuration> 
<repository>${docker.image.prefix}/${project.artifactId}</repository> 
</configuration> 
</plugin> 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-dependency-plugin</artifactId> 
<executions> 
<execution> 
<id>unpack</id> 
<phase>package</phase> 
<goals> 
<goal>unpack</goal> 
</goals> 
<configuration> 
<artifactItems> 
<artifactItem> 
<groupId>${project.groupId}</groupId> 
<artifactId>${project.artifactId}</artifactId> 
<version>${project.version}</version> 
</artifactItem> 
</artifactItems> 
</configuration> 
</execution> 
</executions> 
</plugin> 
</plugins> 
</build> 
</project>

在Eclipse Luna Service Release 2 (4.4.2)构建时出现错误:

Failure to transfer org.apache.maven.plugins:maven-war-plugin:pom:3.1.0 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-war-plugin:pom:3.1.0 from/to central (http://repo.maven.apache.org/maven2): connect timed out

你已尝试删除.lastupdated文件并强制更新Maven项目,但问题依旧。


解决方案尝试

1. 手动安装插件到本地仓库

既然自动下载超时,我们可以手动下载插件POM并安装:

  • 找到org.apache.maven.plugins:maven-war-plugin:3.1.0的POM文件下载到本地
  • 打开命令行,执行以下命令(替换路径为你实际下载的文件路径):
mvn install:install-file -Dfile=/你的下载路径/maven-war-plugin-3.1.0.pom -DgroupId=org.apache.maven.plugins -DartifactId=maven-war-plugin -Dversion=3.1.0 -Dpackaging=pom

安装完成后回到Eclipse,重新更新项目即可。

2. 切换国内Maven镜像

官方仓库访问慢或超时是常见问题,配置阿里云镜像能有效解决:

  • 打开本地Maven配置文件~/.m2/settings.xml(如果没有则新建),添加镜像配置:
<settings>
  <mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <mirrorOf>central</mirrorOf>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>
</settings>

保存后,在Eclipse右键项目选择Maven > Update Project,勾选Force Update of Snapshots/Releases后更新。

3. 检查并配置代理(若网络需要)

如果你的网络处于代理环境下,Eclipse可能未配置代理导致无法访问仓库:

  • 打开Eclipse的Window > Preferences > General > Network Connections
  • 将Active Provider设为Manual,添加HTTP和HTTPS的代理地址、端口,必要时填写认证信息
  • 应用设置后重新更新Maven项目。

4. 升级Eclipse的Maven插件

Eclipse Luna自带的Maven插件版本较老,可能存在兼容性问题:

  • 打开Help > Eclipse Marketplace,搜索"Maven Integration for Eclipse"
  • 找到对应的插件点击Update,完成后重启Eclipse再尝试构建。

5. 在POM中显式指定插件版本

在项目POM的<build><plugins>区块中,直接添加maven-war-plugin的配置,强制指定版本:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.1.0</version>
</plugin>

然后执行Maven > Update Project,让Maven重新尝试拉取该插件的依赖。

内容的提问来源于stack exchange,提问作者PDH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:38:53