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

Google App Engine Java8迁移Java11本地服务器启动失败求助

问题根源与修复方案

你的本地服务器启动失败核心原因是依赖版本与Java 11不兼容,具体包括:

  • 老旧的Jersey 2.17内置ASM库无法识别Java 11生成的字节码(版本55),触发IllegalArgumentException
  • App Engine SDK、Objectify等依赖停留在Java 8兼容版本,不支持Java 11运行环境
  • Maven插件版本过旧,对Java 11的编译、打包支持不完善

以下是具体修复步骤:


1. 升级核心依赖版本

修改pom.xml中的依赖,替换为Java 11兼容的版本:

<dependencies>
    <!-- Jakarta JAXB (Java 11+ 兼容版本) -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>3.0.1</version>
        <scope>runtime</scope>
    </dependency>
    <!-- Jersey (修复Java 11字节码兼容问题) -->
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.35</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.35</version>
    </dependency>
    <!-- App Engine SDK (Java 11兼容版本) -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>2.0.15</version>
    </dependency>
    <!-- Objectify (支持Java 11与App Engine Gen2) -->
    <dependency>
        <groupId>com.googlecode.objectify</groupId>
        <artifactId>objectify</artifactId>
        <version>6.1.13</version>
    </dependency>
</dependencies>

2. 更新Maven插件版本

升级插件以适配Java 11的编译、打包与本地运行:

<build>
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.10.0</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <encoding>UTF-8</encoding>
                <release>11</release>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.2</version>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>2.4.0</version>
            <configuration>
                <projectId>cardserver</projectId>
                <version>1</version>
                <cloudSdkVersion>430.0.0</cloudSdkVersion>
            </configuration>
        </plugin>
    </plugins>
</build>

3. 后续操作

  • 执行mvn clean install -U清理本地缓存并重新构建项目
  • 检查web.xml中Jersey的ServletContainer配置,确保未引用过时类
  • 确认appengine-web.xml仅保留java11 runtime配置,移除Java 8专属的过时配置(如<threadsafe>)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 04:37:14