Last active
November 25, 2024 08:49
-
-
Save jedvardsson/5ec22c872a73edda55b248354fc8ca4c to your computer and use it in GitHub Desktop.
Convert output from MacOS /usr/libexec/java_home to json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -o errexit | |
| set -o nounset | |
| set -o pipefail | |
| unset JAVA_VERSION | |
| unset JAVA_ARCH | |
| require_command() { | |
| if ! type $1 1>/dev/null 2>&1; then | |
| echo "Missing command: $1" >&2 | |
| shift | |
| for arg in "${@}"; do | |
| echo "--> $arg" | |
| done | |
| return 1 | |
| fi | |
| } | |
| require_command "jq" "https://jqlang.github.io/jq/" "brew install jq" | |
| java_home --xml | | |
| plutil -convert json - -o - | | |
| jq 'map(. | {"name": .JVMName, "platform_version": .JVMPlatformVersion, "path" : .JVMHomePath, "bundle_id": .JVMBundleID, "version": .JVMVersion, "vendor" : .JVMVendor, "enabled": .JVMEnabled, "arch": .JVMArch})' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[ { "name": "Oracle GraalVM 23.0.1+11.1", "platform_version": "23.0.1", "home_path": "/Library/Java/JavaVirtualMachines/graalvm-23.jdk/Contents/Home", "bundle_id": "com.oracle.java.jdk", "version": "23.0.1", "vendor": "Oracle Corporation", "enabled": true, "arch": "arm64" }, { "name": "OpenJDK 23.0.1", "platform_version": "23.0.1", "home_path": "/opt/homebrew/Cellar/openjdk/23.0.1/libexec/openjdk.jdk/Contents/Home", "bundle_id": "net.java.openjdk.jdk", "version": "23.0.1", "vendor": "Homebrew", "enabled": true, "arch": "arm64" } ]