How do I use JDK 7 on Mac OSX?

前端 未结 15 2176
滥情空心
滥情空心 2020-11-29 17:13

I would like to use the WatchService API as mentioned in this link: http://download.oracle.com/javase/tutorial/essential/io/notification.html

After reading around, I

相关标签:
15条回答
  • 2020-11-29 17:24

    Java 9, 10, 11

    Years ago, Apple joined the OpenJDK project, transferring their formerly proprietary macOS-specific JVM code as free-of-cost open-source. Apple ceased distribution of their own branded JVM/JDK, relying on Oracle’s branded releases to include a version for macOS.

    Oracle has recently announced their intention to bring their Oracle-branded JVM release to feature parity with the OpenJDK project, with virtually the same code base. The company even donated their previously commercial tools, Flight Recorder & Mission Control, to the OpenJDK project. This is part of the shift to a new rapid “release train” plan for predictably scheduled versioning of Java and OpenJDK. Notably, the periods for free-of-cost public updates is now shortened. See this 2017-09 announcement and this posting by Mark Reinhold.

    As a result of all this, macOS users of Java have a choice of vendors for a Java implementation. At this point, at least three sources are based on OpenJDK for macOS:

    • Oracle releases of the JDK and JRE, with optional paid support.
    • Azul Systems releasing:
      • Zulu line of free-of-cost JVMs with optional paid support.
      • Zing line of commercial JVMs with special features such as an alternate garbage-collector.
    • OpenJDK source code, roll-your-own compilation & installation (perhaps not practical for most of us).

    Meanwhile, IBM donated code for a JVM to the Eclipse Foundation, now housed in the OpenJ9 project. I wonder if they might support a macOS release as well, though it is too soon to tell.

    Personally, I am currently using the Zulu release of Java 10.0.1 from Azul on macOS High Sierra successfully with IntelliJ 2018.2 to produce Java-backed web apps with Vaadin.

    Installation/Removal

    Both Oracle and Azul provide utterly easy-to-use installers to install the JVM/JDK on your Mac. Verify your installation by using the Terminal.app (or equivalent) to type and run:

    java -version
    

    You will find the Java installations in this folder at the root level of your drive (not in your home folder):

    /Library/Java/JavaVirtualMachines

    Each version from each vendor is found there, in a labeled nested folder. You can delete any installation simply by deleting the nested folder for that version and providing your system password when prompted.

    Java 8

    You can download the Java Development Kit (JDK) for Java 8 for the supported versions of Mac OS X:

    • Mountain Lion (10.8.3+)
    • Mavericks (10.9)
    • Yosemite (10.10)
    • El Capitan (10.11)

    Each version of JVM you install can be found here:

    /Library/Java/JavaVirtualMachines
    

    For more instructions and FAQ, see this Oracle Guide.

    Java 7

    For every release of Java 7 since Update 4, a Mac version has been ready alongside the other platforms. Runs on Macs with 64-bit hardware on Lion (10.7.3+), Mountain Lion (10.8.3+), and Mavericks (10.9.x).

    Oracle announced the official release of the JDK for Java SE 7 Update 4 on Mac OS X (Lion), as of 2012-04-26. No more need for the tricks discussed on this page.

    Installation is simple per these instructions:

    1. Download from the usual place on the Oracle web site.
    2. Mount the DMG.
    3. Run the installer.

    This release has a few limitations, most notably the lack of support for Java Web Start and the Java Plugin for web browsers. That support is expected later this year.

    After installing, read the JDK for Mac ReadMe. Most importantly, if you want Java 7 to be the default, drag it to the top of the list in the Java Preferences app found in your Utilities folder.

    Mac OS X easily supports multiple JVMs simultaneously. Each is now found here:

    /Library/Java/JavaVirtualMachines
    

    Congratulations to the Apple & Oracle teams for their achievement. This geek gets a thrill seeing Mac OS X listed as a "Certified System Configuration".

    Tip: To start Eclipse on a Mac with only Java 7 installed, open the alias file named eclipse rather than the file named Eclipse.app.

    Java 6

    Apple continues to supply an up-to-date implementation of Java 6 for all versions of Mac OS X up through Mountain Lion.

    If you do something that requires Java, such as type "java -version" in Terminal.app, a dialog appears offering to install Java for you. If you accept, installation happens automatically similar to other "Software Updates" from Apple.

    You will find Java installed in this location, different than Java 7 & 8:

    /System/Library/Java/JavaVirtualMachines
    

    Java 6 has reached end-of-life with Oracle as of 2013-02 (unless you have a commercial support agreement with Oracle). So you should be moving to Java 7 or 8.

    Testing New Version

    In Terminal.app, type java -version to verify which version is the current default.

    Deleting Old Versions

    After installing a fresh version, you may want to visit the folder described above to delete old versions. Move the folder to the Trash, and provide your System password complete the move.


    By the way, Apple provides a mailing list for developers’ technical issues related to Java on OS X.

    0 讨论(0)
  • 2020-11-29 17:24

    An easy way to install Java 7 on a Mac is by using Homebrew, thanks to the Homebrew Cask plugin (which is now installed by default).

    Run this command to install Java 7:

    brew cask install caskroom/versions/java7
    
    0 讨论(0)
  • 2020-11-29 17:24

    after installing the 1.7jdk from oracle, i changed my bash scripts to add:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
    

    and then running java -version showed the right version.

    0 讨论(0)
  • 2020-11-29 17:25

    As of December 2017, previously posted links don't work, but JDK 7 can still be downloaded from Oracle Archives (login required):

    http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

    0 讨论(0)
  • 2020-11-29 17:30

    Get cask

    brew tap caskroom/cask
    

    Install java7:

    brew tap caskroom/versions
    brew cask install java7
    

    (I had difficulty finding the download link of java7 on oracle website, as they're just "recommending" java8 )

    EDIT January 2018 (As pointed by Ankur):

    Use zulu7 cask. Zulu is a certified build of OpenJDK produced by Azul Systems that should be around for a long time (they even offer JDK6 builds still).

    brew cask install caskroom/versions/zulu7
    
    0 讨论(0)
  • 2020-11-29 17:34

    The instructions by peter_budo worked perfectly. I had to add the jars under /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/jre/lib/ to my IntelliJ project libraries. Now it works like a charm. Note that I didn't need my IDE itself to run under 1.7; rather, I only needed to be able to compile and run against 1.7. I'll most likely continue to use Apple's JRE for running the IDE since it's probably more stable with respect to graphics routines (Swing, AWT). Like the OP, I was really keen on testing out the new NIO2 API. Looking good so far. Thanks, Peter.

    0 讨论(0)
提交回复
热议问题