I'm trying to infer the Java versions of installed JDKs/JREs. I see a lot of code out there that runs java -version
and parses the output, but that is a bit expensive and annoying to write. Besides, the output of java -version
doesn't include important information like the OS and architecture (especially important nowadays with M1 Macs that can support multiple architectures).
I notice that in all the JDKs that I have installed, there is a release
file with the line JAVA_VERSION="<VERSION>"
.
For example, Amazon Corretto 8 has a release
file that says
cat release
JAVA_VERSION="1.8.0_322"
OS_NAME="Windows"
OS_VERSION="5.1"
OS_ARCH="i586"
SOURCE=""
LIBC=""
And Zulu 17 says
IMPLEMENTOR="Azul Systems, Inc."
IMPLEMENTOR_VERSION="Zulu17.32+13-CA"
JAVA_VERSION="17.0.2"
JAVA_VERSION_DATE="2022-01-18"
LIBC="default"
MODULES="java.base java.compiler java.datatransfer java.xml java.prefs java.desktop java.instrument java.logging java.management java.security.sasl java.naming java.rmi java.management.rmi java.net.http java.scripting java.security.jgss java.transaction.xa java.sql java.sql.rowset java.xml.crypto java.se java.smartcardio jdk.accessibility jdk.internal.jvmstat jdk.attach jdk.charsets jdk.compiler jdk.crypto.ec jdk.crypto.cryptoki jdk.dynalink jdk.internal.ed jdk.editpad jdk.hotspot.agent jdk.httpserver jdk.incubator.foreign jdk.incubator.vector jdk.internal.le jdk.internal.opt jdk.internal.vm.ci jdk.internal.vm.compiler jdk.internal.vm.compiler.management jdk.jartool jdk.javadoc jdk.jcmd jdk.management jdk.management.agent jdk.jconsole jdk.jdeps jdk.jdwp.agent jdk.jdi jdk.jfr jdk.jlink jdk.jpackage jdk.jshell jdk.jsobject jdk.jstatd jdk.localedata jdk.management.jfr jdk.naming.dns jdk.naming.rmi jdk.net jdk.nio.mapmode jdk.random jdk.sctp jdk.security.auth jdk.security.jgss jdk.unsupported jdk.unsupported.desktop jdk.xml.dom jdk.zipfs"
OS_ARCH="x86_64"
OS_NAME="Darwin"
SOURCE=".:git:bfa6b2cbcbf7"
I'm unable to find a JEP or any other documentation that says this file will always be there, but also unable to find a counterexample. (I'm also not able to find a JEP or documentation about the format of the output of `java -version)
Is it safe to assume that there will always be a release
file with at least a JAVA_VERSION
line?