71

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?

Brad Koch
  • 17,848
  • 18
  • 106
  • 133
Sreekanth P
  • 1,065
  • 2
  • 12
  • 14

6 Answers6

82

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.

CarlosZ
  • 7,601
  • 1
  • 20
  • 16
  • if you run Spring boot fully executable jar, you could by this to specify -D property, e.g. JAVA_OPTS="-Dspring.profiles.active=test" ./myapp.jar – zhuguowei Nov 22 '15 at 16:06
17

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

Madcat
  • 311
  • 2
  • 7
16

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" 
jmj
  • 232,312
  • 42
  • 391
  • 431
6

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.

Michael Lihs
  • 6,690
  • 14
  • 46
  • 75
Pharfar Phystok
  • 411
  • 4
  • 12
  • 14
    This is not strictly correct. A lot of "JVM processes" pay no attention to $JAVA_OPTS at all. For instance, none of the Oracle java commands, Apache "mvn", Apache "ant", ... – Stephen C Jun 21 '13 at 10:20
2

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

There is a _JAVA_OPTIONS environment variable, more about it here

Michael Lihs
  • 6,690
  • 14
  • 46
  • 75
Dmitry V.
  • 316
  • 4
  • 11
0

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

Andorkan
  • 81
  • 5