使用 JAVA_OPTS 环境变量运行 java 没有效果
在 shell 脚本中,我设置了 JAVA_OPTS 环境变量(以启用远程调试并增加内存),然后按如下方式执行 jar 文件:
export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n -Xms512m -Xmx512m"
java -jar analyse.jar $*
但 JAVA_OPTS 环境变量似乎没有任何效果,因为我无法连接到远程- 调试,我发现 JVM 内存没有变化。
可能是什么问题?
PS:我无法在 java -jar analysis.jar $* 命令中使用这些设置,因为我在应用程序中处理命令行参数。
In a shell script, I have set the JAVA_OPTS environment variable (to enable remote debugging and increase memory), and then I execute the jar file as follows:
export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n -Xms512m -Xmx512m"
java -jar analyse.jar $*
But it seems there is no effect of the JAVA_OPTS env variable as I cannot connect to remote-debugging and I see no change in memory for the JVM.
What could be the problem?
PS: I cannot use those settings in the java -jar analyse.jar $*
command because I process command line arguments in the application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以设置
_JAVA_OPTIONS
而不是JAVA_OPTS
。这应该可以在没有$_JAVA_OPTIONS
的情况下工作。You can setup
_JAVA_OPTIONS
instead ofJAVA_OPTS
. This should work without$_JAVA_OPTIONS
.我不知道有哪个 JVM 会真正检查 JAVA_OPTS 环境变量。通常这用在启动 JVM 的脚本中,并且通常只是将其添加到
java
命令行中。这里要理解的关键是,
-jar analysis.jar
位之前 的java
参数只会影响 JVM 和 >不会传递给您的程序。因此,将脚本中的java
行修改为:应该“正常工作”。
I don't know of any JVM that actually checks the
JAVA_OPTS
environment variable. Usually this is used in scripts which launch the JVM and they usually just add it to thejava
command-line.The key thing to understand here is that arguments to
java
that come before the-jar analyse.jar
bit will only affect the JVM and won't be passed along to your program. So, modifying thejava
line in your script to:Should "just work".
在过去 12 年中,进行了一些更改:
环境变量
JDK_JAVA_OPTIONS
:这是从 Java 9 开始执行您想要的操作的推荐方法,请参阅使用 JDK_JAVA_OPTIONS 启动器环境变量,以及这个全面的答案 使用 Java 11 时 JDK_JAVA_OPTIONS 和 JAVA_TOOL_OPTIONS 有什么区别?。环境变量
JAVA_OPTS
:它过去不是,现在也不是标准化选项。一些基于 Java 的工具的 shell 脚本包装器确实会对其进行评估,ZoogieZork 的答案中提供了一个说明其工作原理的示例。环境变量
_JAVA_OPTIONS
(由十六进制提及):现在已弃用/未记录,请参阅Oracle 公告(“添加新的启动器环境变量 JDK_JAVA_OPTIONS
”部分)。In the past 12 years some changes were made:
Environment variable
JDK_JAVA_OPTIONS
: this is the recommended way to do what you wanted starting with Java 9, see Using the JDK_JAVA_OPTIONS Launcher Environment Variable in the Oracle Java 9 documentation, and this comprehensive answer What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11?.Environment variable
JAVA_OPTS
: it was NOT and is NOT a standardized option. Some shell script wrappers for Java based tools do evaluate it, an example of how this works is in the answer from ZoogieZork.Environment variable
_JAVA_OPTIONS
(mentioned by HEX): it is nowadays deprecated/undocumented, see Oracle announcement (section "Add a new launcher environment variable JDK_JAVA_OPTIONS
").