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

JDK1.6+GWT2.4项目编译过慢冻结PC,新手求助

Hey there, let's tackle this GWT compile headache you're dealing with—slow builds and resource hogging are the worst, especially when you're still getting up to speed with the framework. Let's break down what's going on and some actionable fixes tailored to your setup (JDK 1.6, GWT 2.4, Maven, 8GB i5 PC):

First, let's recap your situation

  • Initial issue: Running mvn gwt:compile spiked memory to 4GB, generated a 2.7GB gwtXXXXXbyte-cache temp file, maxed out your CPU, froze your PC, and eventually crashed after an hour.
  • After config tweaks: No more memory errors, but compile time blew out to 5 hours—definitely not ideal.

Here are targeted fixes to speed up your GWT compile:

1. Move GWT's working directory to a faster storage

That massive byte-cache file is being written to your system's temp directory, which might be on a slow mechanical HDD. Redirect it to your project's build directory (preferably on an SSD) to cut down on I/O time:
Add this to your gwt-maven-plugin configuration:

<workDir>${project.build.directory}/gwt-work</workDir>

This also makes it easier to clean old cache files with mvn clean.

2. Tune localWorkers and parallel compilation

Your Intel i5 likely has 4 physical threads (or 8 with hyper-threading). Setting localWorkers to 2 is underutilizing your CPU, but going too high can cause thread contention. Try setting it to 3—it's a sweet spot for most 4-core CPUs with your memory constraints.

3. Optimize JVM parameters for JDK 1.6

Your current JVM args have some settings that might be hurting performance on a multi-core CPU. Let's adjust them:

  • Remove -XX:+AggressiveOpts—it's unstable in JDK 1.6 and can cause unexpected slowdowns.
  • Add -XX:+CMSClassUnloadingEnabled—critical for GWT, as it loads hundreds of temporary classes during compilation; this lets the GC clean them up instead of cluttering PermGen.
  • Swap incremental CMS mode for full CMS compaction (better for multi-core):
<extraJvmArgs>-Xms2048M -Xmx5120M -Xss1024k 
  -XX:PermSize=256m -XX:MaxPermSize=768m 
  -XX:+UseConcMarkSweepGC -XX:+UseCompressedOops 
  -XX:+CMSParallelRemarkEnabled -XX:+UseParNewGC 
  -XX:+CMSClassUnloadingEnabled -XX:+CMSCompactAtFullCollection 
  -XX:CMSFullGCsBeforeCompaction=0</extraJvmArgs>

4. Analyze compile bottlenecks with a report

Enable GWT's compile report to see exactly which parts of your code are taking the longest to compile. Add this to your plugin config:

<compileReport>true</compileReport>

After compilation, check target/gwt/compile-report/index.html—it'll show you slow classes or modules that you can optimize (e.g., split large classes, remove unused imports).

5. Trim down your GWT module

Double-check your it.reply.Login.gwt.xml file:

  • Remove any <inherits> tags for modules you don't actually use (e.g., extra GWT widgets or third-party libraries).
  • Ensure <source> tags only include code that needs to be compiled to JavaScript—exclude server-side or non-GWT-compatible classes.
    Smaller module scope = faster compilation.

6. Bonus: Clean up old caches and dependencies

Sometimes stale cache files or corrupted Maven dependencies can slow things down. Run:

mvn clean install -U

The -U flag forces Maven to update dependencies, and clean wipes old GWT work files.

Example optimized plugin config

Putting it all together, here's what your plugin should look like:

<build>
  <finalName>webcls</finalName>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>gwt-maven-plugin</artifactId>
      <version>2.4.0</version>
      <configuration>
        <workDir>${project.build.directory}/gwt-work</workDir>
        <extraJvmArgs>-Xms2048M -Xmx5120M -Xss1024k 
          -XX:PermSize=256m -XX:MaxPermSize=768m 
          -XX:+UseConcMarkSweepGC -XX:+UseCompressedOops 
          -XX:+CMSParallelRemarkEnabled -XX:+UseParNewGC 
          -XX:+CMSClassUnloadingEnabled -XX:+CMSCompactAtFullCollection 
          -XX:CMSFullGCsBeforeCompaction=0</extraJvmArgs>
        <server>true</server>
        <logLevel>INFO</logLevel>
        <draftCompile>true</draftCompile>
        <localWorkers>3</localWorkers>
        <module>it.reply.Login</module>
        <compileReport>true</compileReport>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>compile</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Extra tips for long-term improvement

  • If your project allows, upgrade to JDK 1.7—GWT 2.4 supports it, and it has better garbage collection and performance than 1.6.
  • Consider splitting your large Login module into smaller sub-modules (e.g., login-ui, common-utils). GWT can compile multiple modules in parallel, which cuts down total time.
  • While it's a bigger lift, upgrading to a newer GWT version (like 2.8+) would give you access to much faster incremental compilation and performance optimizations.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:38:42