Use of java (specifically on older macOS)
chrischavez at gmx.us
Mon Dec 13 01:10:23 UTC 2021
Sent: Monday, December 13, 2021 at 12:18 AM
From: "Gerben Wierda"
> Which means that MacPorts solr8 runs using macOS native java and not one from MacPorts itself. I thought the MacPorts stuff was supposed to be fully independent (except for Xcode).
The JDK ports are an exception in that they install to the usual system-wide location of /Library/Java/JavaVirtualMachines rather than in the MacPorts prefix. Presumably this is an unavoidable requirement for them to be usable system-wide on macOS.
> $ java -version
> java version "12.0.2" 2019-07-16
> Java(TM) SE Runtime Environment (build 12.0.2+10)
> Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
> $ ls -l /usr/bin/java
> lrwxr-xr-x 1 root wheel 74 Aug 10 2019 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
> $ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
> -rwxr-xr-x 1 root wheel 58336 Jul 11 07:48 /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
> That java is starting to get old, the last update was the last Security Update from macOS Mojave
Your Java 12 installation comes from somewhere else. Apple has not shipped Java with/for macOS for a long time. The java, javac, etc. commands present in system paths are merely wrappers which require a separately-installed Java runtime to do anything useful.
> I also have Oracle Java SE 8 installed:
> $ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
> java version "1.8.0_311"
> Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
> Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)
> Basically, I am rather confused about java numbering. I know I have the latest Oracle Java install and that my macOS Mojave version had its last update in the summer of 2021. I am also somewhat confused about MacPorts using the standard macOS Java which has a higher number but is an older version.
> Can somebody enlighten me?
macOS will reportedly pick the installation with the latest Java version, unless a specific Java version/installation is requested e.g. by the JAVA_HOME environment variable.
> And shouldn’t ports that use java not depend on a java that comes with (old, outdated) java’s in macOS? But install and use an open source version instead? Or use the one from Oracle if available?
Because JDK is not a lightweight dependency, it seems somewhat desirable for ports to be flexible when specifying a Java requirement, and allow using an already-installed JDK/JRE if compatible (including one not provided by MacPorts). The Java PortGroup allows specifying a required Java version (either a minimum version or an exact version), and a fallback JDK port to install if a compatible version isn’t already present (hopefully an LTS version: e.g. 8, 11, or 17 from OpenJDK; other vendors may have LTS for other versions).
Christopher A. Chavez
More information about the macports-users