2

Is there any system-wide or account-wide configuration file I can use? I don't want to use MAVEN_OPTS because forked java processes won't pick it up then.

There is a lib/jvm.cfg, though I don't understand its semantics or whether it can be used for that purpose at all.

user1050755
  • 11,218
  • 4
  • 45
  • 56
  • Can you use alias? For example: `alias java='java –XX:+UseG1GC'` – Krzysztof Atłasik Apr 01 '19 at 22:09
  • Possible duplicate of [Difference between \_JAVA\_OPTIONS JAVA\_TOOL\_OPTIONS and JAVA\_OPTS](https://stackoverflow.com/questions/28327620/difference-between-java-options-java-tool-options-and-java-opts) – the8472 Apr 02 '19 at 21:58

1 Answers1

2

AFAIK, there is no system-wide way to set JVM flags for all Java processes. There are various environment variables that are conventionally used by 3rd-party tools. Some of them are described here:

However, these do not apply when you launch an application directly using the java command.

The "jvm.cfg" file does not help. It implements an (undocumented) mechanism for configuring the java command's "known JVMs" and the JVM options that select them. (For details, refer to src/java.base/share/native/libjli/java.c in the OpenJDK 11 source tree.)


This leaves you with clunky / kludgy / fragile alternatives like:

  • defining java as a shell function or alias
  • writing a wrapper script for the java command and putting it on your PATH ahead of the real java binary.
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216