ANT_OPTS -Xmx1024m not working

I set ANT_OPTS in the environment "-Xms256m -Xmx1024m". After that, I can not run ant files from the command line. This generates an error:

"Error initializing the virtual machine. Could not reserve enough space for the heap of objects. Failed to create the Java virtual machine.

Although I have enough available physical memory (more than 2048 m available) to allocate 1024 m for ANT_OPTS, it still throws the above error. Could there be another reason why I cannot set Xmx to 1024 meters?

+6
source share
3 answers

You do not indicate which OS you are using. If you work on Windows (especially 32-bit), I often see distribution problems larger than, say, 800 MB in a heap, no matter what actual memory you have. Actually, this is not Windows bashing: the Windows JVM wants to allocate all its heap in a continuous fragment, and if it cannot start it.

I think that the maximum Java memory in Windows XP explains the problem well and how you can solve it.

+4
source

Anyway, here's how to fix it:

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

  • Variable Name: _JAVA_OPTIONS
  • Variable Value: -Xmx512M

or

set _JAVA_OPTS="-Xmx512M" 

or

Modify the ant call as shown below.

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

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

+4
source

Whatever you choose initially as the minimum heap, the JVM will try to allocate at startup. It seems that on your computer (suppose a 32-bit machine), the JVM cannot allocate, and the JVM does not start. Try setting -Xms to 128 or less. It should work.

0
source

Source: https://habr.com/ru/post/886092/


All Articles