1

I was able to play around with the latest early access binary for Project Loom by downloading the file from http://jdk.java.net/loom/, extracting it (I had a directory called jdk-18), setting the JAVA_HOME env var to the jdk-18 directory, and adding the bin subdirectory for the build to the beginning of my PATH env var. I was able to use the build to compile and run a Java program using the virtual thread preview features.

But this feels like a very manual process. I like how SDKMAN manages JDKs on my system. How can I set up this early access build (or any other JDK build for that matter) as an entry in the list of JDKs managed by SDKMAN, so that I could change to it, for example, by typing sdk default java <my-jdk-18-name>?

Matt Welke
  • 1,441
  • 1
  • 15
  • 40

2 Answers2

3

SDKMAN has a feature called "Install Local Version(s)" (https://sdkman.io/usage#localversion).

So, to set up a custom build of the JDK with SDKMAN, I can download and install the JDK wherever I want and then link it to SDKMAN so that it's useable like any other JDK managed by SDKMAN:

wget https://download.java.net/java/early_access/loom/7/openjdk-18-loom+7-288_linux-x64_bin.tar.gz
tar -xf openjdk-18-loom+7-288_linux-x64_bin.tar.gz
mv jdk-18/ 18-loom
sdk install java 18-loom $(realpath 18-loom/)

After installing and linking:

~/javas > sdk default java 18-loom

Default java version set to 18-loom
~/javas > which java
/home/matt/.sdkman/candidates/java/current/bin/java
~/javas > java --version
openjdk 18-loom 2022-03-15
OpenJDK Runtime Environment (build 18-loom+7-288)
OpenJDK 64-Bit Server VM (build 18-loom+7-288, mixed mode, sharing)
Matt Welke
  • 1,441
  • 1
  • 15
  • 40
0

Joggling PATH variable for managing mulptiple JDK's was the only straightforward way of doing things for many years, however general automation of this process slowly improves.

Currently on I use jenv, generally any POSIX OS should be supported, I use it on Mac (brew install jenv).

Its main drawback for me — if you include its init $(jenv init -) in terminal RC script, it will delay terminal start-up for a few seconds.

Switch for particular folder would look like: jenv local <my-custom-jdk-name>

Alex G
  • 21
  • 1
  • Ah, so is the idea that I'd run something like `jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home` (from their home page example) for the directory where I extract my custom build to, like the jdk-18 Project Loom build I reference in my question? jenv requires me to install the JDK, but then once I have, it can manage any JDK I've installed, not just ones from a registry (like sdkman)? – Matt Welke Dec 20 '21 at 01:20
  • Actually, I found a way to do it with sdkman by looking through their GitHub issues: https://github.com/sdkman/sdkman-cli/issues/1016#issuecomment-997524195 – Matt Welke Dec 20 '21 at 01:50