I would like to use the WatchService API as mentioned in this link:http://download.oracle.com/javase/tutorial/essential/io/notification.html
If you don’t, you can download the basic software by visiting a Sun Microsystems Web site. The product that you want to download is known by a few different names. It’s called the Java Development Kit (JDK), the Java Software Development Kit (SDK), and the Java Standard Edition (Java SE). Eclipse for Java How To Install Eclipse and Get Started with Java Programming (on Windows, Mac OS and Ubuntu).
After reading around, I found out that WatchService is part of the NIO class which is scheduled for JDK 7. So, it is in beta form. It's fine.
http://jdk7.java.net/download.html has the JDK which I downloaded and extracted. I got a bunch of folders. I don't know what to do with them.
Then, I read around some more and found that some nice group of people created JDK 7 as a binary so someone like me can install it easily. It is called Open JDK:http://code.google.com/p/openjdk-osx-build/
So, I downloaded the .dmg file and install it. Then I open 'Java Preference' and see that OpenJDK7 is available.
So, now I feel that I can start trying out WatchService API. From the tutorial in the first link, the author gave a .java file to test it out first and make sure that it is running. Here is the link to the file:http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
So, I boot up Eclipse (actually I use STS) and create a new Java project and choose JaveSE-1.7 in the 'use an execution environment JRE:'. Under the src folder, I copy pasted the WatchDir.java file.
And I still see tons of squiggly red lines. All the 'import.java.nio.*' are all red and I cannot run it as a Java app.
What do I need to do?
Zoe14 Answers
Ben SThis is how I got 1.7 to work with Eclipse. I hope it helps.
- I Downloaded the latest OpenJDK 1.7 universal (32/64 bits) JDKfrom Mac OS/X branch from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- copied the jdk to /Library/Java/JavaVirtualMachines/ next to thedefault 1.6.0 one
- In Eclipse > Preferences > Java > Installed JREs you add a new one, of type MacOS X VM, and set the home as /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home andname Java SE 7 (OpenJDK)
- Click Finish
- Set the added JRE as default
that should be it :)
vectorsizevectorsizeYears 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:
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.
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:
For more instructions and FAQ, see this Oracle Guide.
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:
- Download from the usual place on the Oracle web site.
- Mount the DMG.
- 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:
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.
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:
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.
In Terminal.app, type java -version
to verify which version is the current default.
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.
Basil BourqueBasil BourqueAn 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:
AndrewAndrewI know that some may want to smack me for re-opening old post, but if you feel so do it I just hope this may help someone else trying to set JDK 7 on Mac OS (using IntelliJ).
What I did to get this working on my machine is to:
- followed instructions on Oracle JDK7 Mac OS X Port for general installation
- in IntelliJ open/create new project so you can add new SDK (File > Project Structure)
- select Platform Settings > SDKs, press '+' (plus) sign to add new SDK
- select JSDK and navigate to /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home. Do not get it mistaken with /Users/YOUR_USERNAME/Library/Java/. This will link 4 JARs from 'lib' directory (dt.jar, jconsole.jar, sa-jdi.jar and tools.jar)
- you will need also add JARs from /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/jre/lib (charsets.jar, jce.jar, JObjC.jar, jsse.jar, management-agent.jar, resources.jar and rt.jar)
Get 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).
Jdk 7 Mac
It's possible that you still need to add the JDK into Eclipse (STS). Just because the JDK is on the system doesn't mean Eclipse knows where to find it.
Go to Preferences > Java > Installed JREs
If there is not an entry for the 1.7 JDK, add it. You'll have to point Eclipse to where you installed your 1.7 JDK.
If Eclipse can't find a JRE that is 1.7 compatible, I'm guessing that it just uses your default JRE, and that's probably still pointing at Java 1.6, which would be causing your red squiggly lines.
after installing the 1.7jdk from oracle, i changed my bash scripts to add:
and then running java -version
showed the right version.
How about Netbeans, here is an article how to set it up with NB7:
Maybe similar steps for Eclipse.
As of April 27th there is an offical Oracle release of Java SE 7u4. Download the disk image and run the installer - then see the Mac readme.
MarkMarkThe 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.
What worked for me on Lion was installing the JDK7_u17 from Oracle, then editing ~/.bash_profile to include: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
As of December 2017, previously posted links don't work, but JDK 7 can still be downloaded from Oracle Archives (login required):
ozren1983ozren1983I updated to Yosemite and Android Studio wouldn't clean my projects or Run them on virtual or real device because of the following error:
After some research and trouble shooting, I found that the JDK file that was being pointed to at '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home' wasn't there; all of 'JavaVirtualMachines/1.6.0.jdk/Contents/Home' was missing from '/System/Library/Java'. So, I copied 'JavaVirtualMachines/1.6.0.jdk/Contents/Home' over from '/Library/Java/' to '/System/Library/Java/' and cha ching! I was back in business.
embersofadyingfireembersofadyingfireNot the answer you're looking for? Browse other questions tagged macosjavajava-7 or ask your own question.
I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp.I looked for a Mac version, but I'm a bit surprised to only see downloadable versions for Linux, Windows and Solaris...
Here's the message for Mac:
'Apple Computer supplies their own version of Java. Use the Software Update feature (available on the Apple menu) to check that you have the most up-to-date version of Java for your Mac.'
OK BUT... when I update Java with Mac I have a JRE and not a JDK...
I don't understand why a JDK version doesn't exist that is easily downloadable/installable (like a jar to unzip?) for Mac...
Peter Mortensen16 Answers
What Jdk Should I Download For Mac Download
In a comment under @Thilo's answer, @mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:
This will dynamically assign to JAVA_HOME the location of the first JDK listed in the 'General' tab of 'Java Preferences' utility.
See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html
EDIT:
If you prefer parentheses to backticks for command substitution, this also works:
CœurAs the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).
See: http://developer.apple.com/java/
NOTE This answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download page on Oracle's website now.
JesperJesperFor people using any LION OS X 10.7.X
They uploaded Java SE 6 version 1.6.0_26 available here
Roy CalderonRoy CalderonI bought a MacBook Pro yesterday (Mac OS X v10.8 (Mountain Lion)) and there is no JDK installed by default...
As well as javac, I also found it didn't have packages such as SVN installed. It turns out you can get everything from the Apple developer page (you will need to register with your AppleID). SVN is part of the 'Command Line Tools' package.
This is what happens on a fresh MacBook:
Hopefully this will help out other newbies like me ;)
Peter MortensenMac comes with the JDK, for more information check:
pedromarcepedromarceThe explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library and Mac's JDK doesn't provide it:
(Cf. http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html)
tools.jar does not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jar need to be rewritten accordingly.
It sucks!
Peter MortensenThe easiest way is to use Homebrew. Install Homebrew and then:
You can list all available versions using the following command:brew cask search java
Compiling with -source 1.5 -target 1.5 (in a JDK 6 environment) will honor only language elements that were in 1.5 and prior. Great. But there were no language changes in 6 anyway. Problem with this approach (on Mac with 1.6) is that using classes that came AFTER 1.5 will still compile because they exist in the rt.jar. So one could run in a 1.5 env and get a class not found exception with no prior warning when compiling. I found this out the hard way with javax.swing.event.RowSorterEvent/Listener. Both entered 'Since 1.6' but are not caught with -source 1.5
If you installed brew, cmd below will be helpful:
brew cask install java
As of Mac OS X v10.6 (Snow Leopard), you can run Java 6 in 32-bit mode on either 32-bit or 64-bit Intel processor equipped Macs.
If you cannot upgrade to Snow Leopard, Soy Latte is a pre-compiled version of Java 6 for Intel 32-bit.
Peter MortensenThere are various tricky issues with having multiple versions of Java (Apple's own Java 6 and Oracle JDK 7 or even 8) on one's Mac OS X system, and using different versions for different applications. I spent some time writing up my experience of my experience of installing and configuring various versions of JDK on Mac OS X 10.9.2.
Meng LuMeng LuI think this other Stack Overflow question could help:
It basically says that if you need to compile or execute a Java application with an older version of the JDK (for example 1.4 or 1.5), you can do it using the 1.6 because it is backwards compatible. To do it so you will need to add the parameter -source 1.5
and/or -target 1.5
in the javac options or in your IDE.
JDK is the Java Development Kit (used to develop Java software).
JRE is the Java Runtime Environment (used to run any .jar file 'Java software').
The JDK contains a JRE inside it.
On Windows when you update Java, it updates the JRE automatically.
On Mac you do not have a JRE separated you have it, but inside the JDK, so when you update Java it will update your JRE which is inside your JDK;it doesn't install an JDK for you. You need to get it from somewhere else.
Peter MortensenCheck this awesome tool sdkman to manage your jdk and other jdk related tools with great ease!
e.g.
Rishikesh DarandaleWhat Jdk Should I Download For Mac Windows 10
Rishikesh DarandaleSince most answers are out of date, here's what works as of end of 2018 under the assumption that
- You want to install the GPL version of OpenJDK.[0]
- You do not want to install Homebrew
In that case, grab the desired version from the Oracle GPLv2 OpenJDK site, or from AdoptOpenJDK (not tested by myself yet). In the below I am assuming version 11.0.1 for Mac. Then do in your favorite shell:
[0] Note that the Oracle branded JDK has significant licensing restrictions allowing you its use basically only for testing, i.e., not for production. If you do not have a support agreement with Oracle, then it seems risky to me to use their JDK, especially since the differences to OpenJDK are minimal.
As a rule you cannot install other versions of Java on a Mac than those provided by Apple through Software Update. If you need Java 6 you must have a 64-bit Intel computer. You should always have Java 5 and 1.4 and perhaps 1.3 installed if you have at least OS X 10.4.
Download Java 8 Jdk For Mac
If you have VERY much elbow grease and is willing to work with beta software you can install the OpenJDK under OS X, but I don't think you want to go there.
Thorbjørn Ravn AndersenThorbjørn Ravn Andersen