NetBeans and arbitrary JDK version in macOS

By default, macOS picks up Java version based on highest number that is located here /Library/Java/JavaVirtualMachines. This is quite painful in case you have multiple versions of Java and willing to switch back and forth. You can, of course, export JAVA_HOME like this

> export JAVA_HOME=$(/usr/libexec/java_home -v 11)
> export PATH=${JAVA_HOME}/bin:${PATH}

You can disable Java versions by moving file /Library/Java/JavaVirtualMachines/jdk-##.jdk/Contents/Info.plist to “backup” – Info.plist~. If there is no Info.plist file, this particular version of Java is not taken into account.

Fortunately, in NetBeans, you can pass location of JDK (one that will be used by NetBeans) via --jdkhome argument.

# If you have JDK 11 installed, but you want to run NetBeans 
# with version 1.8 simply point to this particular version
# by passing it's location with --jdkhome argument
> ./netbeans --jdkhome \
/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/

That’s it.

Alternatively, you can modify file etc/netbeans.conf and set value of netbeans_jdkhome=”/path/to/jdk” to location you want to use.