ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Womack <>
Subject RE: java compilation out of memory problem
Date Fri, 06 Jul 2001 15:58:53 GMT
Ming, I had the same problem as you.  I found 2 solutions.

1) Increase the memory partition in the java command that launches Ant.  You
have already seen messages to the effect.  I found that I could compile all
of my files with a 75mb heap, your mileage may vary.  I added these flags:
"-Xms75m -Xmx75m" for the Sun 1.3 jdk that we use.

2) If requiring that much memory to compile is a concern, then use the
foreach task to compile the code a directory at a time.  I wrote the
following tasks to do this, and it works with the default memory heap.
Start by calling the target build_all_by_dir, and then if compiles all of
the .java files, a directory at a time.

    <!-- ===================================================================
    <!-- build_all_by_dir target
    <!-- ===================================================================
    <taskdef name="foreach"
    <target name="build_all_by_dir" depends="init, prepare_dirs">
        <antcall target="build_each_dir">
            <param name="parentDir" value=""/>
            <param name="srcDir" value="${mySrcSir}"/>
            <param name="destDir" value="${myDestDir}"/>
            <param name="classPath" value="${myClasspath}"/>
            <param name="debug" value="${debug}"/>
            <param name="optimize" value="${optimize}"/>

    <!-- ===================================================================
    <!-- build_each_dir target
    <!-- ===================================================================
    <target name="build_each_dir">
        <foreach target="build_each_compile" type="dir">
            <param name="parentDir">
                <item value="${parentDir}"/>
            <param name="srcDir">
                <item value="${srcDir}"/>
            <param name="destDir">
                <item value="${destDir}"/>
            <param name="classPath">
                <item value="${classPath}"/>
            <param name="debug">
                <item value="${debug}"/>
            <param name="optimize">
                <item value="${optimize}"/>
            <param name="src.subdir">
                <fileset dir="${parentDir}" includes="*"/>
    <!-- ===================================================================
    <!-- build_each_compile target
    <!-- ===================================================================
    <target name="build_each_compile">
        <echo message="checking: ${parentDir}${src.subdir}"/>
        <javac srcdir="${srcDir}"
            <patternset excludesfile="${srcDir}/build_excludes" />
        <antcall target="build_each_dir">
            <param name="parentDir" value="${parentDir}${src.subdir}/"/>

It is very verbose with the output, and I am not sure it is a good argument
for including foreach functionality in Ant, but it works.  I tried to
combine these three tasks into a smaller number, but didn't have much
success and ran out of time.  If someone out there can find a way to reduce
them, I would love to hear about it.  I really dislike that I have to
constantly set the same params over and over.

To use these tasks, you will need to include the ForeachTask class in your
ant classpath.  You can find the source here:

Hope this helps, and if anyone has any comments or suggestions, I am all


-----Original Message-----
From: Ming-Fang Wang []
Sent: Friday, July 06, 2001 5:26 AM
Subject: java compilation out of memory problem


I run javac task on Ant to compile about 1250 java files. It starts
fine, but after compiling several java programs ( about 20 of them) I
got a run-out-of-memory error. The message also suggests using a
switch  -J-mx<nmbs>. I cannot find any document mentioning such a
switch. Has any one encountered such a situation and got a solution to
this problem?



View raw message