Installing a new Java JDK on a Mac

Updating Java on a Mac is easy, it’s just a case of installing a new JDK and recreating the symbolic link that is used to point to the current JDK.

Download the Java .dmg for mac from the Oracle website, then run through the installer.

That will install Java for you, but your default Java installation won’t be updated to point to the new version, but fortunately its easy to correct that

Open up a terminal and type

 cd /System/Library/Frameworks/JavaVM.framework/Versions/

You will probably see something like this

 lrwxr-xr-x  1 root  wheel   60 10 Dec 17:23 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/

As you can see, CurrentJDK is pointing to 1.6

Delete the symbolic link

 sudo rm CurrentJDK

Then recreate it and point to the version of Java you want to use as the default

 sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/ CurrentJDK
 

Then if you run java -version you should now see 1.7

 java version "1.7.0_45"
 Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
 Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

Stop Mac OS X creating hidden files when using the tar command

Last week I found something quite frustrating with the tar command on Mac OS X, it likes to put hidden files into archives when you tar them up, it doesn’t give you any warning, just does it.

Creating a tar, and then having a look at its contents, you’ll see something like this :

JamesMac:staging-area JElsey$ tar -tf MyApplication.tar.gz 
src/
src/._MyApplication.cmd
src/MyApplication.cmd
src/._MyApplication.properties
src/MyApplication.properties
src/lib/
src/lib/._anExternalJar.jar
src/lib/anExternalJar.jar

Notice the files prefixed with “._”.

You can quite easily stop this, by setting the following environment variable (I prefer to set this up in the bashrc_profile):

COPYFILE_DISABLE=1; export COPYFILE_DISABLE

Then, tar up the files again, and you should see those hidden files no longer.

JamesMac:staging-area JElsey$ tar -tf MyApplication.tar.gz 
src/
src/MyApplication.cmd
src/MyApplication.properties
src/lib/
src/lib/_anExternalJar.jar

Failing that, you could also install GNU tar instead of the Mac version.

How to show hidden files in the Mac OS Finder

Frustrated, that I recently couldn’t find my maven settings.xml file because the Mac OS X Finder doesn’t show hidden files by default, I found that the following can correct that

  1. Open a terminal
  2. Type this : defaults write com.apple.finder AppleShowAllFiles TRUE
  3. Kill any open finder sessions by typing (note the capital F) : killall Finder
  4. Re open the Finder, and you should now be able to see hidden files.

You can also reverse the above by changing TRUE to FALSE.

Hope this helps