Mac, CommandBox, Java and Me

Whilst trying to define the version Java to be used by a Lucee server under CommandBox, I found an issue with the version of Lucee (5.3.4.80 at the time of writing) within CommandBox 5.0.1 and Java 11.0.7_10 which stopped CommandBox starting. This lead me down a rabbit hole which I'll try and capture here.

When installing the AdoptOpenJDK Java implementation with HomeBrew you can only choose the latest version. For example, brew cask install adoptopenjdk11 will install 11.0.7_10 at the time of writing. You can't specify, say, 11.0.4_11 for example. But I did find a way, so bear with me.

First visit the AdoptOpenJDK HomeBrew repository and navigate to the Casks directory. Find the major version you want to install and select the appropriate Ruby file. In my case that will be adoptopenjdk11.rb. Then select the History button to see previous commits of that file. Find the point release you want and click the <> button to move to that place in the commit history. Navigate again to the Cask directory and open the Ruby file again. For me that is https://github.com/AdoptOpenJDK/homebrew-openjdk/blob/87a1e6ad33006b9137e4959fad8f800536988ae5/Casks/adoptopenjdk11.rb. Copy the url value from the file, for me that is https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.4%2B11.4/OpenJDK11U-jdk_x64_mac_hotspot_11.0.4_11.pkg and paste it into your browser. That will download the package installer to your computer.

Start the installer and accept all the default choices. Check the install has worked with /usr/libexec/java_home -V and you should see something like...

11.0.4, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
1.8.0_242, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

...depending on any other versions of Java you may have installed.

Now we need to move the 11.0.4 version out of the way because any future install will overwrite the adoptopenjdk-11.jdk directory. So mv /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk /Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk to rename it. Now /usr/libexec/java_home -V will show.

11.0.4, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk/Contents/Home
1.8.0_242, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

I now have a Java 11.0.4 install that I can point my Lucee server to in CommandBox with the server set jvm.javaHome="/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk/Contents/Home" command.

Next, repeat the process for Java 11.0.6 for CommandBox to use as v11.0.7 seems to be incompatible.

Alternatively you can get CommandBox to install a version of Java in it's local CommandBox Home. You can find out what versions are available with the java search version=openjdk11 release= command. From there you can choose a version to install when the server starts up with server start javaversion=openjdk11_jre_x64_mac_hotspot_jdk-11.0.4+11 which will update the server.json file. See https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/custom-java-version#automatic-java-download


Firstly install Java as intended with the brew cask install adoptopenjdk11 command. Check the install has worked with /usr/libexec/java_home -V and you should see something like...

11.0.7, x86_64:	   "AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
1.8.0_242, x86_64: "AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64: "Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:  "Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

...depending on any other versions of Java you have installed.

Then visit the AdoptOpenJDK HomeBrew repository and navigate to the Casks directory. Find the major version you want to install and select the appropriate Ruby file. In my case that will be adoptopenjdk11.rb. Then select the History button to see previous commits of that file. Find the point release you want and click the <> button to move to that place in the commit history. Navigate again to the Cask directory and open the Ruby file again. For me that is https://github.com/AdoptOpenJDK/homebrew-openjdk/blob/87a1e6ad33006b9137e4959fad8f800536988ae5/Casks/adoptopenjdk11.rb. Copy the url value from the file, for me that is https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.4%2B11.4/OpenJDK11U-jdk_x64_mac_hotspot_11.0.4_11.pkg and paste it into your browser. That will download the package installer to your computer.

Start the installer and accept all the default choices. Trying /usr/libexec/java_home -V again will show.

11.0.4, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
1.8.0_242, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

Now we need to move the 11.0.4 version out of the way because HomeBrew think the current version of Java is the 11.0.7 we installed earlier. So mv /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk /Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk to rename it. Now /usr/libexec/java_home -V will show.

11.0.4, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk/Contents/Home
1.8.0_242, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

As HomeBrew still thinks that the current version of Java that it installed is 11.0.7 we can get it to reinstall it with brew cask reinstall adoptopenjdk11. Now when we /usr/libexec/java_home -V we get...

11.0.7, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
11.0.4, x86_64:	"AdoptOpenJDK 11"	/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.4.jdk/Contents/Home
1.8.0_242, x86_64:	"AdoptOpenJDK 8"	/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
1.8.0_162, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
1.8.0_92, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home

So now we have two differnt Java 11 point releases available to us.