使用 JAVA_OPTS 环境变量运行 java 没有效果 [英] Running java with JAVA_OPTS env variable has no effect
问题描述
在shell脚本中,我设置了JAVA_OPTS环境变量(开启远程调试和增加内存),然后执行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 $*
但似乎 JAVA_OPTS 环境变量没有影响,因为我无法连接到远程调试,而且我看到 JVM 的内存没有变化.
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.
可能是什么问题?
PS:我不能在 java -jar analysis.jar $*
命令中使用这些设置,因为我在应用程序中处理命令行参数.
PS: I cannot use those settings in the java -jar analyse.jar $*
command because I process command line arguments in the application.
推荐答案
我不知道有任何实际检查 JAVA_OPTS
环境变量的 JVM.通常这用于启动 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 the java
command-line.
这里要理解的关键是-jar analysis.jar
位之前的java
参数只会影响JVM并且不会传递给您的程序.因此,将脚本中的 java
行修改为:
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 the java
line in your script to:
java $JAVA_OPTS -jar analyse.jar $*
应该正常工作".
这篇关于使用 JAVA_OPTS 环境变量运行 java 没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!