Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Mac comes with, and occasionally updates, JDKs 1.4 through 1.6. You can see the versions you have installed in this directory:</p> <ul> <li>/System/Library/Frameworks/JavaVM.framework/Versions</li> </ul> <p>This is how you change the JDK</p> <p><strong>1. Command Line Java</strong></p> <p>My Java is coming from /usr/bin/java, which points off to one of the versions in the 'Versions' dir described above. To change the version of the JDK you're getting here, use the Java Preferences application under Applications -> Utilities -> Java:</p> <p><img src="https://i.stack.imgur.com/86r8T.png" alt="enter image description here"></p> <p>You can drag the JDK you'd like to the top and it should be reflected immediately from the command line: hostname% java -version java version "1.5.0_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_16-133, mixed mode) hostname% java -version java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)</p> <p><strong>2. Scripts and Applications That Use Java</strong></p> <p>Generally, other built-in applications or one that you install will use the JAVA_HOME environment variable to pick a JDK. By default, you won't have this set, and Mac-specific versions of startup scripts will usually create one by using the CurrentJDK link in the Java 'Versions' directory. The steps to add environment variables are documented in this article, but I can save you a little time. Create a directory .MacOSX in your home directory and add a file called environment.plist. Here are the entire contents of my ~/.MacOSX/environment.plist file:</p> <p> </p> <pre><code>&lt;!-- When changing this, also run Java Preferences and change there. --&gt; &lt;key&gt;JAVA_HOME&lt;/key&gt; &lt;string&gt;/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home&lt;/string&gt; </code></pre> <p> With this value set, all processes started as you will have JAVA_HOME available to them. Since this file is read when you log in, you'll have to log out/in once after you create or edit this file.</p> <p><strong>Special case: NetBeans</strong> </p> <p>The IDE I use is NetBeans, but the following idea probably applies to other large applications as well. When NetBeans is installed, it will pick a JDK to use and hard code it in a properties file. If you want it to rely on the JAVA_HOME that you're now setting in <strong>environment.plist</strong>, you just need to edit one file. Edit this file:</p> <ul> <li>/Applications/NetBeans/NetBeans\ 6.5.app/Contents/Resources/NetBeans/etc/netbeans.conf</li> </ul> <p>..and you can set the JDK by changing this line:</p> <p><strong>netbeans_jdkhome=$JAVA_HOME</strong></p> <p>Note that, as the netbeans.conf file points out, you can always force a different JDK to be used by specifying it on the command line when starting the IDE. For your copying and pasting pleasure, here is the command to use to start it from terminal (I'm giving the 'help' option in this case). If you're using a different version, autocomplete ought to help with the version part of the path:</p> <ul> <li>/Applications/NetBeans/NetBeans\ 6.5.app/Contents/MacOS/netbeans --help</li> </ul> <p><strong>Recap</strong></p> <p>To recap, you can switch JDKs for your whole system by using the Java Preferences application along with changing the value in your environment.plist file. To switch on the fly, use the Preferences app and set a new value for JAVA_HOME in whatever terminal you're using, though some apps like NetBeans will still pick up the system value and you should specify the desired JDK on the command line.</p> <p>Resources where I found this solution: <a href="https://blogs.oracle.com/bobby/entry/switching_jdks_on_mac" rel="nofollow noreferrer">https://blogs.oracle.com/bobby/entry/switching_jdks_on_mac</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload