JAVA_OPTS vs JAVA_TOOL_OPTIONS vs _JAVA_OPTIONS: the difference
Codemia Knowledge Hub ·
All three pass JVM arguments through the environment, but at different levels. JAVA_TOOL_OPTIONS is the only one defined by the JVM specification (JVMTI) and is picked up by every compliant JVM. _JAVA_OPTIONS is a HotSpot-specific extension that overrides everything. JAVA_OPTS is not recognized by the JVM at all; it is a convention used by startup scripts like Tomcat's catalina.sh and JBoss's standalone.sh. Picking the wrong one means settings are silently ignored or leak into processes you did not mean to change.
JAVA_TOOL_OPTIONS
Defined in the JVMTI (JVM Tool Interface) specification. Every compliant JVM checks it on startup and prepends its contents to the command-line arguments.
- HotSpot prints a
Picked up JAVA_TOOL_OPTIONSconfirmation to stderr, and there is no flag to suppress it. - Its options are prepended, so explicit command-line arguments override them.
- It affects every Java process started in the environment, including
javac,jps,jstack, and build tools (Maven, Gradle) that spawn child JVMs.
_JAVA_OPTIONS
A HotSpot (Oracle/OpenJDK) extension. It is not part of any specification and does not exist in all JVM implementations.
- Its options are appended to the command line, so they override explicit command-line arguments, which can silently change behavior that was set on purpose.
- It also prints a stderr pickup message.
- IBM J9, GraalVM native-image and other non-HotSpot JVMs may not recognize it.
JAVA_OPTS
The JVM never reads this variable. It exists only as a convention in startup scripts.
- It works only if the script reads it. Tomcat's
catalina.sh, WildFly'sstandalone.shand some others add$JAVA_OPTSto thejavacommand they build. - It has no effect when you run
javadirectly. - No pickup message is printed, because the JVM never sees it.
Side-by-side comparison
| Feature | JAVA_TOOL_OPTIONS | _JAVA_OPTIONS | JAVA_OPTS |
| Defined by | JVMTI specification | HotSpot implementation | Convention (scripts) |
| Recognized by JVM | Yes (all compliant JVMs) | Yes (HotSpot only) | No |
| Argument position | Prepended (overridden by CLI args) | Appended (overrides CLI args) | Depends on script |
| Prints pickup message | Yes | Yes | No |
Affects javac, jps, etc. | Yes | Yes | No |
Affects direct java -jar | Yes | Yes | No |
| Portable across JVMs | Yes | No (HotSpot only) | N/A |
Which value wins when several are set
The effective command line becomes:
For -Xmx and most JVM flags the last value wins, so the max heap is 1024m from _JAVA_OPTIONS. That is why _JAVA_OPTIONS is considered dangerous: it silently overrides values set explicitly on the command line.
Examples
Default heap size for all Java processes
Forcing a heap size that cannot be overridden
Configuring only Tomcat
Docker containers
Environment variables are the standard way to configure JVM options in containers:
JAVA_TOOL_OPTIONS is the better choice here because it is portable and the orchestrator can override it without changing the Dockerfile.
Kubernetes
Remote debugging
This opens a debug port on every Java process, including mvn and gradle commands.
Which one to use
| Scenario | Recommended Variable | Reason |
| Default settings for all Java processes | JAVA_TOOL_OPTIONS | Portable, overridable, spec-compliant |
| Tomcat/WildFly/JBoss configuration | JAVA_OPTS | Read by the server's startup script |
| Force a setting that cannot be overridden | _JAVA_OPTIONS | Appended last, overrides CLI (use sparingly) |
| Docker/Kubernetes environment | JAVA_TOOL_OPTIONS | Clean, portable, works with all JVMs |
| Debugging a single application | CLI arguments | No side effects on other processes |
| CI/CD pipeline defaults | JAVA_TOOL_OPTIONS | Affects build tools and tests uniformly |
Mistakes with JVM environment variables
- Expecting
JAVA_OPTSto work withjava -jar. The JVM does not read it.JAVA_OPTS="-Xmx1024m"followed byjava -jar myapp.jarleaves the heap unchanged. UseJAVA_TOOL_OPTIONS. - Setting
_JAVA_OPTIONSglobally and forgetting it. It overrides CLI arguments, so it can change the behavior of build tools, IDEs and test runners. A global_JAVA_OPTIONS="-Xmx256m"can cause out-of-memory errors in Maven builds that need more heap. - Stderr noise. Both
JAVA_TOOL_OPTIONSand_JAVA_OPTIONSprint a message on every JVM startup, which can trigger false alerts in scripts that parse stderr. It cannot be suppressed. - Affecting unintended processes. Setting
JAVA_TOOL_OPTIONSin a shell profile means every Java process in that shell inherits it, includingjavac,jps,keytool, Maven, Gradle and IDE-launched processes. Scope it to one command when possible:JAVA_TOOL_OPTIONS="-Xmx1g" java -jar myapp.jar. - Mixing up prepend and append.
JAVA_TOOL_OPTIONSis prepended (CLI wins);_JAVA_OPTIONSis appended (it wins). - Relying on
_JAVA_OPTIONSon non-HotSpot JVMs. IBM Semeru, Azul Zing or GraalVM native images may ignore it entirely. UseJAVA_TOOL_OPTIONSfor portability.
Related reading
- Difference between <? super T> and <? extends T> in Java
- Difference between applicationContext.xml and spring-servlet.xml in Spring Framework
- Difference between @Before, @BeforeClass, @BeforeEach and @BeforeAll
- Difference between Codahale metrics and Dropwizard metrics
- Difference between CompletableFuture, Future and RxJava''s Observable
- Difference between <contextannotation-config> and <contextcomponent-scan>
- Difference between Controller and RouterFunction in Spring 5 WebFlux
- Difference between DeferedResult and CompletableFeature
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.