Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use JDK 7 on Mac OSX?

Tags:

java

macos

java-7

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 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?

like image 507
okysabeni Avatar asked Jun 07 '11 15:06

okysabeni


People also ask

Does macOS come with JDK?

How do I know if I have Java installed on my Mac? Mac OS X 10.6 and below: Apple's Java comes pre-installed with your Mac OS. Mac OS X 10.7 (Lion) and above: Java is not pre-installed with Mac OS X versions 10.7 and above. To get the latest Java from Oracle, you will need Mac OS X 10.7.


2 Answers

This is how I got 1.7 to work with Eclipse. I hope it helps.

  1. I Downloaded the latest OpenJDK 1.7 universal (32/64 bits) JDK from Mac OS/X branch from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
  2. copied the jdk to /Library/Java/JavaVirtualMachines/ next to the default 1.6.0 one
  3. 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 and name Java SE 7 (OpenJDK)
  4. Click Finish
  5. Set the added JRE as default

that should be it :)

like image 189
vectorsize Avatar answered Oct 28 '22 22:10

vectorsize


Oracle has released JDK 7 for OS X.

like image 43
Mukund Avatar answered Oct 28 '22 22:10

Mukund