7

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 ?

trincot
  • 317,000
  • 35
  • 244
  • 286
Vivek Bandhu
  • 71
  • 1
  • 1
  • 2
  • It should be allocating only 265Mbs and not 1024Mb initially. What's your OS? Have you tried just using ANT_OPTS="-Xms64m". 64Mb should be the default. This will figure out if there's a memory issue or the way ANT_OPTS is being interpreted. Have you tried modifying the Ant shell script under $ANT_HOME/bin/ant or the Ant batch script %ANT_HOME%/bin/ant.bat to echo more information? You can add "set -xv" to the Ant shell script. – David W. Apr 17 '11 at 20:50

3 Answers3

6

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.

h3xStream
  • 6,293
  • 2
  • 47
  • 57
Sudhakar
  • 3,104
  • 2
  • 27
  • 36
  • Didn't work for me. I tried setting the variable using the `set` and it didn't create it. Then I added it manually going to the Environment Variables button in the Advanced System Properties and re-ran my `ant tagversion` command and same thing. This was on Windows 7. – vapcguy Jun 09 '17 at 14:37
5

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.

Community
  • 1
  • 1
Richard Steele
  • 2,227
  • 1
  • 15
  • 14
0

What ever you set initially as minimum heap, the JVM will try to allocate at start up.It seems in your machine (32 bit machine I assume) the JVM is unable to allocate and JVM start up fails. Try setting -Xms to 128 or less. It should work.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • And where is this set? – vapcguy Jun 09 '17 at 14:39
  • Never mind, I figured out that you run the command on a command line: `java -Xms128m`, for example. Maybe commonplace for some to already know, but I think it should've been in the answer. – vapcguy Jun 09 '17 at 16:16