开发者

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_OP开发者_JAVA百科TS, but still it throws the above error. Can there be any other reason why I cannot set Xmx to 1024m ?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜