使用 JAVA_OPTS 环境变量运行 java 没有效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2011311/
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
Running java with JAVA_OPTS env variable has no effect
提问by Ashika Umanga Umagiliya
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:
在shell脚本中,我已经设置了JAVA_OPTS环境变量(启用远程调试和增加内存),然后我执行jar文件如下:
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.
但似乎 JAVA_OPTS 环境变量没有影响,因为我无法连接到远程调试,而且我看到 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.
PS:我无法在java -jar analyse.jar $*
命令中使用这些设置,因为我在应用程序中处理命令行参数。
采纳答案by ZoogieZork
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.
我不知道任何实际检查JAVA_OPTS
环境变量的JVM 。通常这用于启动 JVM 的脚本中,它们通常只是将它添加到java
命令行中。
The key thing to understand here is that arguments to java
that come beforethe -jar analyse.jar
bit will only affect the JVM and won'tbe passed along to your program. So, modifying the java
line in your script to:
要了解这里的关键问题是,参数java
是来之前的-jar analyse.jar
位只会影响JVM并不会沿着你的程序通过。因此,java
将脚本中的行修改为:
java $JAVA_OPTS -jar analyse.jar $*
Should "just work".
应该“正常工作”。
回答by HEX
You can setup _JAVA_OPTIONS
instead of JAVA_OPTS
. This should work without $_JAVA_OPTIONS
.
您可以设置_JAVA_OPTIONS
而不是JAVA_OPTS
. 这应该可以在没有$_JAVA_OPTIONS
.