How do I use the JAVA_OPTS environment variable?

JavaJvm

Java Problem Overview


How do I use the JAVA_OPTS variable to configure a web server (a linux server)?

How can I set -Djava.awt.headless=true using JAVA_OPTS?

Java Solutions


Solution 1 - Java

JAVA_OPTS is the standard environment variable that some servers and other java apps append to the call that executes the java command.

For example in tomcat if you define JAVA_OPTS='-Xmx1024m', the startup script will execute java org.apache.tomcat.Servert -Xmx1024m

If you are running in Linux/OSX, you can set the JAVA_OPTS, right before you call the startup script by doing

JAVA_OPTS='-Djava.awt.headless=true'

This will only last as long as the console is open. To make it more permanent you can add it to your ~/.profile or ~/.bashrc file.

Solution 2 - Java

Just figured it out in Oracle Java the environmental variable is called: JAVA_TOOL_OPTIONS rather than JAVA_OPTS

Solution 3 - Java

JAVA_OPTS is environment variable used by tomcat in its startup/shutdown script to configure params.

You can set it in linux by

export JAVA_OPTS="-Djava.awt.headless=true" 

Solution 4 - Java

JAVA_OPTS is not restricted to Tomcat’s Java process, but passed to all JVM processes running on the same machine.

Use CATALINA_OPTS if you specifically want to pass JVM arguments to Tomcat's servlet engine.

Solution 5 - Java

Actually, you can, even though accepted answer saying that you can't.

There is a _JAVA_OPTIONS environment variable, more about it here

Solution 6 - Java

As stated in these links below, you can edit JAVA_OPTS for Wildfly/JBoss in bin/standalone.conf

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSreekanth PView Question on Stackoverflow
Solution 1 - JavaCarlosZView Answer on Stackoverflow
Solution 2 - JavaMadcatView Answer on Stackoverflow
Solution 3 - JavajmjView Answer on Stackoverflow
Solution 4 - JavaPharfar PhystokView Answer on Stackoverflow
Solution 5 - JavaDmitry V.View Answer on Stackoverflow
Solution 6 - JavaAndorkanView Answer on Stackoverflow