用JAVA_OPTS env变量运行java

时间:2023-01-07 17:19:28

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 env变量的影响,因为我无法连接到远程调试,我看到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 $ *命令中使用这些设置,因为我在应用程序中处理命令行参数。

2 个解决方案

#1


41  

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 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:

这里要理解的关键是,在-jar analyse.jar位之前的java参数只会影响JVM,不会传递给您的程序。因此,将脚本中的java行修改为:

java $JAVA_OPTS -jar analyse.jar $*

Should "just work".

应该“正常工作”。

#2


77  

You can setup _JAVA_OPTIONS instead of JAVA_OPTS. This should work without $_JAVA_OPTIONS.

您可以设置_JAVA_OPTIONS而不是JAVA_OPTS。这应该没有$ _JAVA_OPTIONS。

#1


41  

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 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:

这里要理解的关键是,在-jar analyse.jar位之前的java参数只会影响JVM,不会传递给您的程序。因此,将脚本中的java行修改为:

java $JAVA_OPTS -jar analyse.jar $*

Should "just work".

应该“正常工作”。

#2


77  

You can setup _JAVA_OPTIONS instead of JAVA_OPTS. This should work without $_JAVA_OPTIONS.

您可以设置_JAVA_OPTIONS而不是JAVA_OPTS。这应该没有$ _JAVA_OPTIONS。