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

VSCode中运行Maven GWT应用遇HTTP 404及启动失败问题排查

问题

通过以下命令生成默认Maven GWT应用:

$ mvn -B archetype:generate \
    -DarchetypeGroupId=org.codehaus.mojo \
    -DarchetypeArtifactId=gwt-maven-plugin \
    -DarchetypeVersion=2.8.1 \
    -DgroupId=com.mycompany \
    -DartifactId=my-app \
    -Dversion=1.0-SNAPSHOT \
    -Dmodule=MyModule

运行mvn clean gwt:run时出现两个问题:

  1. 浏览器打开后显示HTTP ERROR 404
  2. VSCode中执行命令时,点击启动默认浏览器无响应,控制台报错:

[ERROR] Failed to execute goal
org.codehaus.mojo:gwt-maven-plugin:2.8.1:run (default-cli) on project
com.mycompany: Command failed with status 127: [ERROR] /bin/sh -c
'/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java' '-Xmx512m'
'com.google.gwt.dev.DevMode' '-gen'
'/home/username/Documents/projects/mycompany/target/.generated' '-war'
'/home/username/Documents/projects/mycompany/target/appname-1.0-SNAPSHOT'
'-logLevel' 'INFO' '-port' '8888' '-codeServerPort' '9997'
'-startupUrl' 'module.html' '-sourceLevel' '1.8'
'com.mycompany.appname

未修改的pom.xml如下:

<?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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany</groupId>
  <artifactId>mycompany-api</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Archetype for GWT</name>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwt.version>2.8.1</gwt.version>

    <!-- GWT 2.8 requires 1.8 -->
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.release>1.8</maven.compiler.release>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>${gwt.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <!-- Output classes directly into the webapp, so that IDEs "mvn process-classes" update them in DevMode -->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

    <plugins>

      <!-- Mojo's Maven Plugin for GWT -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.8.1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test</goal>
              <goal>generateAsync</goal>
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see 
          gwt-maven-plugin documentation at codehaus.org -->
        <configuration>
          <runTarget>module.html</runTarget>
          <modules>
            <module>com.mycompany.module</module>
          </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
原因与解决办法

1. HTTP 404错误

核心问题是生成命令参数与pom.xml配置不匹配:

  • 生成命令指定-DartifactId=my-app,但pom.xml中<artifactId>是mycompany-api
  • 生成命令指定-Dmodule=MyModule,但pom.xml中gwt插件的<module>是com.mycompany.module,<runTarget>是module.html(GWT会根据模块名生成对应入口HTML,即MyModule.html)

修复步骤:

  • 修改pom.xml的<artifactId>为my-app
  • 修改gwt插件的<module>为com.mycompany.MyModule(groupId+模块名)
  • 修改<runTarget>为MyModule.html

2. VSCode中运行报错(状态码127)

状态码127表示命令无法找到依赖的可执行文件或参数错误:

  • 报错命令行末尾截断,显示com.mycompany.appname,说明模块名配置错误,导致GWT DevMode无法定位正确模块
  • VSCode终端环境可能缺少浏览器或Java的环境变量,导致自动启动浏览器失败

修复步骤:

  • 先解决上述pom配置不匹配问题,确保模块名正确
  • 若浏览器无法自动打开,手动访问http://localhost:8888/MyModule.html(替换为正确的入口路径)
  • 检查VSCode终端的PATH环境变量,确认Java和浏览器的可执行文件路径已包含其中

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 22:34:58