用JAVA_OPTS env变量运行java [英] Running java with JAVA_OPTS env variable
问题描述
在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 env变量的影响,因为我无法连接到远程调试和我看到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 analyse.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的脚本,它们通常只是将它添加到 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.
这里要理解的关键是 java
的参数之前的 -jar analyse.jar
bit只会影响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 env变量运行java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!