How to set or change the default Java (JDK) version on macOS?

First run /usr/libexec/java_home -V which will output something like the following: Matching Java Virtual Machines (3): 1.8.0_05, x86_64: “Java SE 8” /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home 1.6.0_65-b14-462, x86_64: “Java SE 6” /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 1.6.0_65-b14-462, i386: “Java SE 6” /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home Pick the version you want to be the default (1.6.0_65-b14-462 for arguments sake) then: export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462` or you can specify just … Read more

How to set JAVA_HOME environment variable on Mac OS X 10.9?

If you’re using bash, all you have to do is: echo export “JAVA_HOME=\$(/usr/libexec/java_home)” >> ~/.bash_profile If you’re using zsh (which probably means you’re running macOS Catalina or newer), then it should instead be: echo export “JAVA_HOME=\$(/usr/libexec/java_home)” >> ~/.zshrc In either case, restart your shell. If you have multiple JDK versions installed and you want it … Read more

Access restriction: The type ‘Application’ is not API (restriction on required library rt.jar)

Here is the code: package mscontroller; import javax.swing.*; import com.apple.eawt.Application; public class Main { public static void main(String[] args) { Application app = new Application(); app.setEnabledAboutMenu(true); AMEListener listener = new AMEListener(); app.addApplicationListener(listener); JFrame mainFrame = new JFrame(“Application Menu Example”); mainFrame.setSize(500, 500); mainFrame.setVisible(true); } } here is the error: Exception in thread “main” java.lang.Error: Unresolved compilation … Read more