19

I'm using _JAVA_OPTIONS to set some defaults for Java on RHEL. It works fine but now every time I start java I get the following message

 Picked up _JAVA_OPTIONS: -foo -bar -baz

is it possible to keep the options but suppress the display of this message.

3 Answers 3

15

Java is often called with absolute paths like /usr/bin/java, which makes this answer useless in some cases, and requires more to make it work in others.

That solution I found requires writing a wrapper shell script that redirects STDERR through a filter removing the offending line. It has to be placed in the $PATH before the java binary it wraps and be called with plain java, which java or similar (or your tool has to be configured to use it)

It relies on the bash ability to create a subshell with parentheses (command), and redirect java’s STDERR to its STDIN command1 2> >(command2). Finally, the process in the subshell needs to redirect its filtered input to STDOUT again so that java programs can still use STDERR.

#!/bin/bash
/usr/bin/java "$@" 2> >(grep -v "^Picked up _JAVA_OPTIONS:" >&2)
1
  • Probably terrible practice, but it's for a docker image and I got tired of all the red during docker build -- but I renamed ${JAVA_HOME}/bin/java to java2 and put a modified version of this script in there as java (with chmod +x). Worked like a charm! Jul 28, 2019 at 19:57
4

Or you can put this in your shell startup / profile files:

_SILENT_JAVA_OPTIONS="$_JAVA_OPTIONS"
unset _JAVA_OPTIONS
alias java='java "$_SILENT_JAVA_OPTIONS"'
3
  • 1
    that only works when directly invoking java ... through the command line. all java invocations through scripts or other parent processes will be unaffected Dec 7, 2015 at 8:22
  • well, you can change /bin/java to be a shell script that does the same thing if you really want to.
    – spelufo
    Dec 7, 2015 at 9:58
  • even if you don't it will unset the options, so other commands will be affected too. It will silence them by not passing them any options :).
    – spelufo
    Dec 7, 2015 at 10:08
2

This message is output by all standard versions of Java since (I think Java 5). It is certainly present in the source code from Java 6 through Java 15.

It is output by the java command when it sees that the JAVA_TOOL_OPTIONS or _JAVA_OPTIONS environment variable is set and when the user is not privileged. The behavior is hardwired, and the java command doesn't provide a way to suppress it. (If you want more precise details, look at the arguments.cpp file.)

People have requested that Oracle add an option to suppress the message:

JDK-8039152 : Need a way to suppress message when picking up JAVA_TOOL_OPTIONS

but this has been closed as WON'T FIX.


First of all, it is important to understand why this message is output. According to bug report's analysis:

"So that leaves adding an option to suppress the message. Yes, we could do this, but is it a good idea? The reason that the message is issued is that the feature being used is dangerous and the VM should warn about it.

I strongly recommend that we don't try to change this behavior. 03-04-2014"

In short, the message is a WARNING that something potentially dangerous may be happening. Something that could cause java to behave in unexpected (and possibly even insecure) ways.


So what can you do to make the annoying message go away?

The best solution is to not use those variables. Unset them! There are other ways to pass command options to the java command that are less dangerous. If the annoying output is coming from some application that relies on those variables ... raise a bug report for the application.

There are other possible solutions; e.g. filtering the message out of the error stream, or expanding JAVA_TOOL_OPTIONS into the java command line (see other answers).

  • I recommend that you DO NOT do either of these things. Why? Because by suppressing the message you are disabling an important safety feature in the java command.

  • And if you do decide to suppress the message, DO NOT do it by replacing the standard java command with a shell alias or a wrapper script. That is really asking for trouble.

4
  • It is output by the java command when it sees that the JAVA_TOOL_OPTIONS or _JAVA_OPTIONS environment variable is set and when the user is not privileged. What kind of privilege would a user need?
    – Blaisem
    Nov 17, 2022 at 8:46
  • I imagine they mean privileged like an administrator or root user.
    – Paul
    Feb 3, 2023 at 18:15
  • What sort of trouble does a wrapper script invite?
    – Lyle
    Jan 2 at 18:11
  • "What sort of trouble does a wrapper script invite?" - Security vulnerabilities, etcetera.
    – Stephen C
    Feb 27 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .