How to run NetBeans 8 if multiple java version (Java 8 and Java 9) is available on MacOS

After installing Java 9 NetBeans stopped working properly and instead of setting up the default java version to java 8 it was using java 9.

I have figured out a solution to run NetBeans with Java 8 and also having Java 9 on MacOS to test new features available in Java 9.

My approach to switching between different versions of java (in .profile) :

Install both Java versions (Java 8 and Java 9) and also install NetBeans.

Add the below lines in .profile under your user directory.

export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7) # add this line if you have Java 7 installed
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

#create alias to switch instantly with java versions
alias java7='export JAVA_HOME=$JAVA_7_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java9='export JAVA_HOME=$JAVA_9_HOME'

#set default java version
export JAVA_HOME=$JAVA_8_HOME

To run NetBeans 8 with Java 8

Edit the netbeans.conf file

I have found mine under the below directory

/Applications/NetBeans/NetBeans 8.2.app/Contents/Resources/NetBeans/etc

In netbeans.conf file find the keyword “netbeans_jdkhome” as you can see in the below screenshot and change the value to “$JAVA_8_HOME”




Now your NetBeans will work with java 8 and you will be able to use java 9 features separately.



Done!!!

Comments

Popular posts from this blog

Java 21 Features With Example

Java 10 and 10 Big Java Milestones