Suppressing the “Picked up _JAVA_OPTIONS” message

13

8

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.

flying sheep

Posted 2013-04-21T13:46:53.230

Reputation: 484

Answers

11

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)

flying sheep

Posted 2013-04-21T13:46:53.230

Reputation: 484

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! – BrainSlugs83 – 2019-07-28T19:57:22.747

2

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"'

spelufo

Posted 2013-04-21T13:46:53.230

Reputation: 141

that only works when directly invoking java ... through the command line. all java invocations through scripts or other parent processes will be unaffected – flying sheep – 2015-12-07T08:22:15.223

well, you can change /bin/java to be a shell script that does the same thing if you really want to. – spelufo – 2015-12-07T09:58:37.993

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 – 2015-12-07T10:08:33.643