[java] Running java with JAVA_OPTS env variable has no effect

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.

This question is related to java shell remote-debugging jvm-arguments

The answer is


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".


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


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to shell

Comparing a variable with a string python not working when redirecting from bash script Get first line of a shell command's output How to run shell script file using nodejs? Run bash command on jenkins pipeline Way to create multiline comments in Bash? How to do multiline shell script in Ansible How to check if a file exists in a shell script How to check if an environment variable exists and get its value? Curl to return http status code along with the response docker entrypoint running bash script gets "permission denied"

Examples related to remote-debugging

Adb over wireless without usb cable at all for not rooted phones Run local python script on remote server Eclipse : Failed to connect to remote VM. Connection refused. Accessing localhost (xampp) from another computer over LAN network - how to? Work on a remote project with Eclipse via SSH Running java with JAVA_OPTS env variable has no effect Remote debugging a Java application Debug JavaScript in Eclipse

Examples related to jvm-arguments

Is JVM ARGS '-Xms1024m -Xmx2048m' still useful in Java 8? What does -Xmn jvm option stands for How to increase IDE memory limit in IntelliJ IDEA on Mac? What does -XX:MaxPermSize do? “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G What is the largest possible heap size with a 64-bit JVM? How to give Jenkins more heap space when it´s started as a service under Windows? Increasing the JVM maximum heap size for memory intensive applications Java stack overflow error - how to increase the stack size in Eclipse? Difference between -XX:+UseParallelGC and -XX:+UseParNewGC