79

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
  • 19,267
  • 19
  • 110
  • 137
Sreekanth P
  • 1,187
  • 2
  • 12
  • 16

6 Answers6

92

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
  • 8,281
  • 1
  • 21
  • 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
23

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

Madcat
  • 379
  • 2
  • 7
18

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
  • 237,923
  • 42
  • 401
  • 438
5

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
  • 7,460
  • 17
  • 52
  • 85
Pharfar Phystok
  • 425
  • 4
  • 12
  • 16
    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
  • 7,460
  • 17
  • 52
  • 85
Dmitry V.
  • 336
  • 4
  • 11
-1

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

Andorkan
  • 89
  • 6