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

运行DropWizard应用时遇Unsupported class file major version 61错误求助

问题分析与解决方案

核心错误原因

Unsupported class file major version 61 对应JDK17的类文件版本,报错说明项目中存在不兼容JDK17的依赖库。从错误堆栈来看,具体是Guava/Guice相关组件无法处理JDK17编译的类文件。

解决方案

1. 升级Guava版本

错误堆栈中出现com.google.common.cache相关类,老版本Guava(如低于30.1-jre)不支持JDK17的类文件版本。在pom.xml中更新Guava依赖:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>31.1-jre</version> <!-- 或更高兼容JDK17的版本 -->
</dependency>

2. 升级Guice版本

堆栈中涉及com.google.inject组件,旧版Guice(如低于5.0.1)对JDK17兼容性不足,更新依赖:

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>5.1.0</version> <!-- 或更高版本 -->
</dependency>

3. 确认Maven编译配置

确保pom.xml中maven-compiler-plugin的source和target都设置为17,避免编译产生不兼容的类文件:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
                <source>17</source>
                <target>17</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

4. 清理并重新构建项目

执行以下Maven命令清理旧编译文件并重新构建:

mvn clean install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 07:02:26