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)
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
tojava2
and put a modified version of this script in there asjava
(withchmod +x
). Worked like a charm! – BrainSlugs83 – 2019-07-28T19:57:22.747