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

创建Spring MVC项目时Maven报错:Cannot access defaults field of Properties

解决Maven创建webapp项目时的"Cannot access defaults field of Properties"错误

错误信息

Exception java.lang.ExceptionInInitializerError: Cannot access defaults field of Properties [in thread "Worker-6: Creating maven-archetype-webapp"]

当前Pom.xml内容

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.aryan.spring</groupId>
  <artifactId>springmvc1</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>springmvc1 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>springmvc1</finalName>
  </build>
</project>

解决方案

  • 匹配JDK与Maven版本:这个错误核心原因是版本不兼容,比如JDK17+搭配Maven3.6.x及以下,或者低版本JDK用过高版本Maven。推荐组合:
    • JDK8 → Maven3.6.x
    • JDK11/17 → Maven3.8.x及以上
  • 强制指定编译JDK版本:在Pom.xml的<build>节点下添加插件配置,避免环境变量冲突:
    <build>
      <finalName>springmvc1</finalName>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
            <source>1.8</source> <!-- 根据实际JDK版本修改,如11、17 -->
            <target>1.8</target>
          </configuration>
        </plugin>
      </plugins>
    </build>
    
  • 清理Maven缓存:执行命令mvn clean install -U,强制更新依赖并清除本地缓存文件,解决缓存损坏问题
  • 检查Tomcat依赖兼容性:如果已引入Tomcat依赖,确保版本和Spring MVC、JDK匹配,比如Spring MVC5.x配Tomcat9.x,Spring MVC6.x配Tomcat10.x

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 23:25:57