使用GWT-Maven时,如何为GWT编译器提供更多内存?

时间:2012-05-15 16:43:02

标签: gwt maven gwt-compiler gwt-maven-plugin

我们有一个运行GWT插件的Maven构建版(gwt-maven)。不幸的是,它的内存不足。

我是否需要为Maven本身提供更多堆,还是需要为GWT提供更多堆?知道如何为pom.xml文件指定这个吗?

3 个答案:

答案 0 :(得分:5)

我认为应该配置extraJvmArgs选项。

答案 1 :(得分:3)

在gwt-maven-plugin的配置标记下添加extraJvmArgs标记。

示例 -

        <!-- GWT Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <dependencies>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-user</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-dev</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-servlet</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
            </dependencies>
            <!-- JS is only needed in the package phase, this speeds up testing -->
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                documentation at codehaus.org -->
            <configuration>
                <runTarget>app.html</runTarget>
                <!-- Turning This on after understanding soyc and when deferredjs count is 48.cache.js -->
                <!-- https://developers.google.com/web-toolkit/articles/fragment_merging -->
                <fragmentCount>25</fragmentCount>
                -->
                <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
                <!-- Turn This on for generating soyc. This does not work if closure compiler is turned on.-->
                <!-- Start Generating SOYC -->
                <compileReport>true</compileReport>
                <compilerMetrics>true</compilerMetrics>
                <soycDetailed>true</soycDetailed>
                <!-- End Generating SOYC -->
                <disableCastChecking>true</disableCastChecking>
                <disableClassMetadata>true</disableClassMetadata>
                <enableClosureCompiler>true</enableClosureCompiler>
                <optimizationLevel>9</optimizationLevel>
                <style>${gwt.style}</style>
                <module>${gwtModule}</module>
                <encoding>${project.build.sourceEncoding}</encoding>
                <strict>true</strict>
                <logLevel>INFO</logLevel>
                <copyWebapp>true</copyWebapp>
                <hostedWebapp>
                    ${project.build.directory}/${project.artifactId}
                </hostedWebapp>
                <extraJvmArgs>-Xmx896M -Xms896m -XX:PermSize=64m -XX:MaxPermSize=128m</extraJvmArgs>
                <!-- <extraJvmArgs>-Xmx896M -Xms896m -XX:PermSize=64m -XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC -server</extraJvmArgs> -->
            </configuration>
        </plugin>

答案 2 :(得分:1)

我在一个大型GWT项目中遇到了这个错误。内存不足时可能会看到的错误是:

[ERROR] OutOfMemoryError: Increase heap size of lower gwt.jjs.maxThreads
java.lang.OutOfMemoryError: Java heap space

extraJvmArgs选项需要与MAVEN_OPTS环境变量(this is a possible explanation)一起设置。我还设置了Java -Dgwt.compiler.localWorkers=x选项以减少并发编译线程的数量(我将x设置为1,但您可以使用它来查找有效的内容)。

有关您应该使用extraJvmArgs选项的设置示例,请参阅此post

请注意,您可能需要将extraJvmArgs选项直接添加到插件元素配置中 - 请参阅https://stackoverflow.com/a/5822929/157605