ANT_OPTS -Xmx1024m 不起作用

发布于 2024-11-02 11:49:02 字数 231 浏览 2 评论 0原文

我将环境中的 ANT_OPTS 设置为“-Xms256m -Xmx1024m”。设置此后,我无法从命令提示符运行 ant 文件。它向我抛出一个错误:

“VM 初始化期间发生错误 无法为对象堆保留足够的空间 无法创建 Java 虚拟机。”

虽然我有足够的可用物理内存(超过 2048m 可用)来为 ANT_OPTS 分配 1024m,但它仍然抛出上述错误。是否还有其他原因导致我无法将 Xmx 设置为 1024m ?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潇烟暮雨 2024-11-09 11:49:02

无论如何,以下是解决方法:

转到开始->控制面板->系统->高级(选项卡)->环境变量->系统变量->新建:

  • 变量名称:_JAVA_OPTIONS
  • 变量值: -Xmx512M

set _JAVA_OPTS="-Xmx512M"

更改 ant 调用,如下所示。

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

然后使用 ant 再次构建文件。
这对我有用。

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.

末骤雨初歇 2024-11-09 11:49:02

您没有提及您正在运行的操作系统。如果您使用的是 Windows(尤其是 32 位),我经常会看到分配超过 800MB 作为堆的问题,无论您有多少实际可用内存。这并不是真正的 Windows 攻击:Windows JVM 希望在连续的块中分配其所有堆,如果不能,它将无法启动。

我认为Windows XP上的Java最大内存很好地解释了这个问题以及你如何尝试解决它。

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.

瞎闹 2024-11-09 11:49:02

无论你最初设置的最小堆是什么,JVM都会在启动时尝试分配。在你的机器(我假设是32位机器)中,JVM似乎无法分配并且JVM启动失败。尝试将 -Xms 设置为 128 或更小。它应该有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文