Search

I'll be at


I support





Subscribe

Recent entries

Archives by subject

Archives by date

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
17
Sep

Setting Current JDK programmatically on Mac

A few days back I was looking for a way to change the CurrentJDK symbolic link on my Mac. I had found this nice script somewhere (don't quite remember where). But is is very useful.

#!/bin/sh

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

CURJDK="`readlink CurrentJDK`"
echo Current JDK version: $CURJDK

if [ "$1" == "" ]; then
echo Installed versions:
ls
exit
fi

VERFOUND=`ls | grep $1 | head -n 1`

if [ "$VERFOUND" != "$1" ]; then
BASE="`basename $0`"
echo Error: Could not change JDK-- version $1 not installed!
echo Run $BASE without arguments to see a list of installed versions.
exit 127
fi

echo You must now enter your Mac OS X password to change the JDK.
sudo ln -fhsv $1 CurrentJDK

Save it as a file name of your choice. I saved it as "SetJDK.sh". Give it execute permissions, and run the script.

Comments

  • John Barrett's Gravatar John Barrett said:

    I have that same script, not sure where I got it too, but it works great.
    Can I ask how you run it? I have to open the file in pico, then to copy and paste it in the terminal, and then run it. I would be easier to just run it.

    I am a newbie at this, but do you just add the ".sh" to it?

    Thanks,
    John

  • Indy Nagpal's Gravatar Indy Nagpal said:

    Hi John.

    To run it, go to the directory where you've saved it, and then put a period and forward slash, followed by the name of the script.

    So in my case to run it I'd do ./SetJDK.sh

    And oh, make sure you have permissions to execute the script as well.

  • John Barrett's Gravatar John Barrett said:

    I had the file named SetJDK and re named it to SetJDK.sh,and I moved into my home directory,a nd apply the "./SeJDK.sh" and this works, thank you so much. I know see to run the script I use the "./" this is great`-`


    Thanks again
    John