Tuesday, April 7, 2009

Bookmark and Share

When using the JUnit task for Apache Ant I recently came across the following error:

1
2
3
4
5
6
7
8
9
10
...
[junit] Error occurred during initialization of VM
[junit] Could not reserve enough space for object heap
[junit] Could not create the Java virtual machine.
[junit] java.io.FileNotFoundException: /home/.../junitvmwatcher995964737.properties (No such file or directory)
[junit]     at java.io.FileInputStream.open(Native Method)
[junit]     at java.io.FileInputStream.(FileInputStream.java:106)
[junit]     at java.io.FileReader.(FileReader.java:55)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1028)
...

At first I was rather distracted by the FileNotFoundException, but then I recognized that the message "Could not reserve enough space for object heap" might be a pointer to the actual problem.

My build file contained a target for the execution of JUnit tests roughly looking as follows:

1
2
3
4
5
6
7
8
9
10
11
12
...
<target name="junit" depends="jar">
    <junit printsummary="true" fork="true" forkmode="perTest" maxmemory="2048m">

        <classpath>...</classpath>

        <batchtest>
            <fileset dir="${src.dir}" includes="*Test.java"/>
        </batchtest>
    </junit>
</target>
...

When I decreased the value for the maxmemory attribute the error went away. I thought a rather large value here wouldn't do any harm, as I expected that only the actually required amount of memory would be allocated.

But obviously the JUnit task tries to allocate the total amount of memory up-front, causing the test to fail on my system, which only has 2 GB of RAM altogether.

5 comments:

r0b0t said...

Thanks for the muse! I had the same problem and couldn't figure it out.

Unknown said...

Thanks for the feedback. Great to hear, that the post helped you :-)

Ryan said...

Helped me as well. Saw the same symptoms and the problem was exactly as described in your blog post. Thanks!

Anonymous said...

Nice blog as for me. I'd like to read something more concerning that theme.
BTW look at the design I've made myself High class escorts

Anonymous said...

Thanks, It helps me too !!!