Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT_OPTS -Xmx1024m not working

I am setting ANT_OPTS in the environment to "-Xms256m -Xmx1024m". After setting this, I am not able to run ant files from command prompt. It throws me an error of:

"Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine."

Although I have enough physical memory available (more than 2048m available) to allot 1024m for ANT_OPTS, but still it throws the above error. Can there be any other reason why I cannot set Xmx to 1024m ?

like image 342
Vivek Bandhu Avatar asked Apr 17 '11 17:04

Vivek Bandhu


2 Answers

Anyway, here is how to fix it:

Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New:

  • Variable name: _JAVA_OPTIONS
  • Variable value: -Xmx512M

or

set _JAVA_OPTS="-Xmx512M"

or

Change the ant call as shown as below.

<exec>
   <arg value="-J-Xmx512m" />
</exec>

then build the files again using the ant. It worked for me.

like image 90
Sudhakar Avatar answered Sep 19 '22 03:09

Sudhakar


You don't mention what OS you're running. If you're on Windows (especially 32-bit) I often see problems allocating more than, say, 800MB as heap, regardless of how much actual memory you have available. This isn't really Windows bashing: the Windows JVM wants to allocate all of its heap in a contiguous chunk and if it can't it fails to start.

I think Java maximum memory on Windows XP does a good job of explaining the problem and how you might try to solve it.

like image 29
Richard Steele Avatar answered Sep 22 '22 03:09

Richard Steele