欢迎光临
我们一直在努力

使用ant打包出现OutOfMemoryError Java heap space错误

当使用Ant编译大量的Java源文件时,会出现java.lang.OutOfMemoryError:Java heap space异常,解决方法:

<target name="compile" depends="init,create-manifest" description="compile the java code and copy the config files">
        <javac srcdir="${src.dir}" destdir="${root.dir}/WEB-INF/classes" debug="true" fork="true" memoryMaximumSize="512m"  debuglevel="lines,vars,source" includeantruntime="on">
            <compilerarg line="-encoding UTF-8 -source 1.7 -target 1.7" />
            <classpath refid="classpath" />
        </javac>

        <copy todir="${root.dir}/WEB-INF/classes">
            <fileset dir="${src.dir}">
                <exclude name="**/*.java" />
            </fileset>
        </copy>

        <jar destfile="${root.dir}/WEB-INF/lib/${web.jar.filename}" index="true" manifest="${build.dir}/MANIFEST.MF">
            <fileset dir="${root.dir}/WEB-INF/classes" />
        </jar>

        <delete dir="${root.dir}/WEB-INF/classes" />

    </target>

在javac的选项里增加 fork="true" memoryMaximumSize="512m"来加在编译时的内存,实际上我只添加了fork="true"也可以。

参考:

  1. http://blog.csdn.net/stonree/article/details/48470129;
赞(0) 打赏
未经允许不得转载:Ddmit » 使用ant打包出现OutOfMemoryError Java heap space错误

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册