Running java with JAVA_OPTS env variable has no effect
Asked Answered
M

3

59

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 $*

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.

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.

Milord answered 6/1, 2010 at 6:34 Comment(0)
E
60

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.

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 $*

Should "just work".

Earwitness answered 6/1, 2010 at 7:8 Comment(1)
See HEX's answer. That is how you set the options using an environment variable on OS X.Casa
L
105

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

Litha answered 23/7, 2012 at 15:48 Comment(10)
This this the real answer. I went looking around for hours to find this.Casa
@Nerrve Special for you installed Windows XP. Works fine. Are you sure you did everything correctly?Litha
@Nerrve You must create environment variable called _JAVA_OPTIONS. Example: cs417020.userapi.com/v417020976/3764/hwBZ419TXcQ.jpgLitha
oops! you're right. its works! i had made a spelling mistake earlier :P thanks a bunch!Jiva
You may also would use JAVA_TOOL_OPTIONS (#28328120)Preposterous
@Preposterous your suggestion appears to be the correct answer. you should add itGobbet
I can't. I got "Trivial answer converted to comment"Preposterous
Holy moly this worked. Why is this so badly documented?Gunar
Beware: this prints a line to stderrHeadwork
Thanks, I was able to set _JAVA_OPTIONS environment variable using Java 8u282 running in a Docker container and it was picked up!Placement
E
60

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.

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 $*

Should "just work".

Earwitness answered 6/1, 2010 at 7:8 Comment(1)
See HEX's answer. That is how you set the options using an environment variable on OS X.Casa
S
7

In the past 12 years some changes were made:

Socialite answered 13/9, 2022 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.