#!/usr/bin/env bash # # Summary: Configures JAVA_HOME for GUI applications. # # Usage: jenv macos-javahome # # Installs a file located at ~/Library/LaunchAgents/jenv-environment.plist . It sets JAVA_HOME for GUI # applications on startup for the **currently active version of Java**. # # This **must be updated** whenever the version of Java changes. It does not update dynamically. # # cat << EOT > ${HOME}/Library/LaunchAgents/jenv-environment.plist Label my.startup ProgramArguments sh -c launchctl setenv JAVA_HOME $(jenv javahome) ; RunAtLoad EOT launchctl unload ${HOME}/Library/LaunchAgents/jenv-environment.plist || true launchctl load ${HOME}/Library/LaunchAgents/jenv-environment.plist