java 无法通过 .bat 文件设置 jvm 参数/参数(Xmx 和 Xms)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14633998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:54:09  来源:igfitidea点击:

Unable to set jvm parameters/arguments (Xmx and Xms) through .bat file

javabatch-filejvmcomma

提问by IS_EV

I am able to run a java program through eclipse by setting the VM arguments as -Xmx1024m -Xms256M. Now I want to run the same java program (jar) through a .bat file in windows. I am setting the JVM values in the file as follows

通过将 VM 参数设置为 -Xmx1024m -Xms256M,我可以通过 Eclipse 运行 Java 程序。现在我想通过 Windows 中的 .bat 文件运行相同的 java 程序(jar)。我在文件中设置JVM值如下

@echo off
set JAVA_OPTS="-Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError"
java -cp TA.jar com.myClass

But when I run the same program through batch(.bat in windows xp) it throws Out of Memory error and I suspect that the JVM setting through the .bat file is not working.

但是当我通过批处理(Windows xp 中的 .bat)运行相同的程序时,它会抛出内存不足错误,我怀疑通过 .bat 文件的 JVM 设置不起作用。

Can some one please help?

有人可以帮忙吗?

采纳答案by Caesar Ralf

Use the arguments directly

直接使用参数

java -Xmx1024m -Xms256m -XX:+HeapDumpOnOutOfMemoryError -cp TA.jar com.myClass

You don't need to set them at JAVA_OPTIONS. To be sure that your application is using the parameters that you want:

您不需要将它们设置在JAVA_OPTIONS. 确保您的应用程序正在使用您想要的参数:

  • open jvisualvmthat comes with java. Just type "jvisualvm" at command line if you have set java correctly at your path.
  • open the vm started to your application.
  • check under "JVM Arguments" in the "Overview" tab.
  • 打开jvisualvmjava自带的。如果您在路径中正确设置了 java,只需在命令行输入“jvisualvm”。
  • 打开 vm 启动到您的应用程序。
  • 在“概览”选项卡中的“JVM 参数”下检查。

There should be set your jvm options.

应该设置您的 jvm 选项。

回答by Danyel

It should be _JAVA_OPTIONS instead of JAVA_OPTS.

它应该是 _JAVA_OPTIONS 而不是 JAVA_OPTS。