java_home(1) General Commands Manual java_home(1)

java_home - return a value for $JAVA_HOME

/usr/libexec/java_home [options]

The java_home command returns a path suitable for setting the JAVA_HOME environment variable. It determines this path from the user's preferred JVM based on configured environment variables. Additional constraints may be provided to filter the list of JVMs available. By default, if no constraints match the available list of JVMs, the default order is used. The path is printed to standard output.

Filters the returned JVMs by version (as if JAVA_VERSION had been set in the environment). Example versions: "11.0", or "14.0.2".

Filters the returned JVMs by the architecture they support (as if JAVA_ARCH had been set in the environment). Example architectures: "x86_64", or "arm64".

Immediately fails when filters return no JVMs; does not print out the path to the default $JAVA_HOME.

Executes the command at $JAVA_HOME/bin/<command> and passes the remaining arguments. Any arguments to select which $JAVA_HOME to use must precede the --exec option.

Prints a list of all matching JVMs and associated properties as an XML plist to stdout.

Prints a list of all matching JVMs and architectures to stderr.

Brief usage information.

/usr/libexec/java_home helps users set a $JAVA_HOME in their login rc files, or provides a way for command-line Java tools to use the most appropriate JVM which can satisfy a minimum version or architecture requirement. The --exec argument can invoke tools in the selected $JAVA_HOME/bin directory, which is useful for starting Java command-line tools from launchd plists without hardcoding the full path to the Java command-line tool.

$ export JAVA_HOME=`/usr/libexec/java_home`
% setenv JAVA_HOME `/usr/libexec/java_home`
July 15, 2020