使用JAVA_OPTS env变量运行Java无效 [英] Running java with JAVA_OPTS env variable has no effect

查看:143
本文介绍了使用JAVA_OPTS env变量运行Java无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.通常,这在启动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位之前 位出现的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 env变量运行Java无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆