Jump to content

Setting Java 6 is the default JRE in OS X


14 posts in this topic

Recommended Posts

I've been working on basic java development over the past 6 months or so and I'm going to be doing a lot more of it as I go into university. One thing that struck me as rather odd is that even after downloading the "developer's preview" of JDK 6, JDK/JRE 5 remains the default. This is incredibly annoying as when I want to run bytecode compiled using JDK 6 on my Ubuntu and Windows machines OS X just spits out an error message. Is there any way to assign JDK/JRE6 as the default on OS X?

 

Thanks in advance.

Link to comment
Share on other sites

Hm well I found a brute force method of doing this by replacing the contents of my /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0 with those of my /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0 folder.

Link to comment
Share on other sites

  • 3 weeks later...

Hi there,

 

I have a really nice solution. Just create a file like "switchJDK.sh", making it executable (chmod +x switchJDK.sh) and you can switch between your default JDK in seconds. Simply execute the script (name$ ./switchJDK.sh 1.6.0). If you run it without parameters it will show you the JDKs installed. You can switch back and forth between JDKs as often as you want. Very nice.. I found this script a while ago.. So all the credit goes to "unknown":-)

 

#!/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

 

 

 

 

Best

 

Nikolai Manek

http://www.nikotel.com

Link to comment
Share on other sites

  • 2 years later...

I created a version of this code for changing the JRE instead of the JDK, this may be useful for the more technically challenged out there. You can grab the code from my blog here: http://www.piranhamethod.com/2010/04/insta...0-5-8-or-later/

 

Hi there,

 

I have a really nice solution. Just create a file like "switchJDK.sh", making it executable (chmod +x switchJDK.sh) and you can switch between your default JDK in seconds. Simply execute the script (name$ ./switchJDK.sh 1.6.0). If you run it without parameters it will show you the JDKs installed. You can switch back and forth between JDKs as often as you want. Very nice.. I found this script a while ago.. So all the credit goes to "unknown":-)

 

#!/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

 

 

 

 

Best

 

Nikolai Manek

http://www.nikotel.com

Link to comment
Share on other sites

  • 1 month later...

To the original post:

 

You can change the JDK and JRE by using the Java Preferences application (Applications/Utilities/Java Preferences). There you have 2 preferences list (one for applets and other for local apps), you can simply drag your preferred version to top.

 

But if you want to check it and do the job for the user on your application, the bash script should work.

Link to comment
Share on other sites

  • 4 weeks later...

El coniglio,

 

Can you help me out here please. I am trying to run the "System Info app", which you so gracious made and shared, thanks; but I check my 10.5.8 java version, it says "1.5.0_24" I have installed java 1.6.0 for 10.5.8 it is showing in S/L/Frameworks/....

 

I made the above script, ran it and it spits out current version as 1.6.0 but when I run java -version I still see 1.5.0_24.

 

In Java Preferences in utilities only shows J2SE 5.0 32-bit & J2SE 1.4.2 32-bit, in the upper and lower frame. How can I correct this please, thanks.

Link to comment
Share on other sites

El coniglio,

 

Can you help me out here please. I am trying to run the "System Info app", which you so gracious made and shared, thanks; but I check my 10.5.8 java version, it says "1.5.0_24" I have installed java 1.6.0 for 10.5.8 it is showing in S/L/Frameworks/....

 

I made the above script, ran it and it spits out current version as 1.6.0 but when I run java -version I still see 1.5.0_24.

 

In Java Preferences in utilities only shows J2SE 5.0 32-bit & J2SE 1.4.2 32-bit, in the upper and lower frame. How can I correct this please, thanks.

 

How did you install the 1.6 java in your mac? Using the software update? Try to check the links in System/Library/Frameworks/JavaVM.framework/Versions if all seems to be ok try to update manually the link (ln -s).

 

The .app laucher should automatically select the 1.6 vm, so even if you have 1.5 as default, the System Info app should load if the 1.6 was in the system.

Link to comment
Share on other sites

How did you install the 1.6 java in your mac? Using the software update? Try to check the links in System/Library/Frameworks/JavaVM.framework/Versions if all seems to be ok try to update manually the link (ln -s).

 

The .app laucher should automatically select the 1.6 vm, so even if you have 1.5 as default, the System Info app should load if the 1.6 was in the system.

 

Thanks for the reply. I downloaded the "JavaForMACOSX10.5Update.7 Pkg", ran the install, and it update 1.5 to 1.5.0_24 and placed 1.6 & 1.6.0 folders in System/Library/Frameworks/JavaVM.framework/Versions.

 

Next to the 1.6 folder I see current written, and current JDK next to the 1.6.0 folder.

 

Can you walk me through the syntax to update manually the links please? Thanks

Link to comment
Share on other sites

Can you walk me through the syntax to update manually the links please? Thanks

 

I am not 100% sure if just updating the links will do the job, but tomorrow I'll switch between versions and check for modifications. I'm gonna sleep now, tomorrow I'll edit this post to help you out =)

Link to comment
Share on other sites

Hello again and sorry for the delay. I've tracked the directories under /System/Library/Frameworks/JavaVM.framework/Versions/ but I couldn't find how it selects the default vm as it is not by any links. The only way I found to "force" to use a vm was exporting JAVA_HOME and PATH variables, if you really want to keep these set, just add to your /etc/profile, or in ~/.bash_profile as suggested in the howto site that follows.

 

Probably you are not allowed to use the 1.6 vm cause your processor doesn't support 64 bits, and Apple only released the Apple JDK 6 for 64 bit cpus. In this link there is a howto to install a 32bit 1.6 VM: http://netbeans.org/kb/61/java/javafx-jdk6...32-bit-mac.html

 

As described in the site, if you set the links properly in the /System/Library/Frameworks/JavaVM.framework/Versions/ the applications (and probably the Java Prefereces) will detect it and let you select it as default.

 

Hope this helps =)

Link to comment
Share on other sites

el coniglio, thanks for the very useful link. I tried it, but could not get it going. I want to believe, because my CPU is AMD, and I think it was made for Intel. Much thanks.

 

Did you install the SoyLatte JDK 6 and it didn't work? Did you set the links to make it the default vm and checked with java -version? I've installed this jdk on a computer and could use it with no problems.

 

If it is viable, an update to snow leo will also solve the issue, heh.

Link to comment
Share on other sites

Yes I did, followed the steps to the letter, but still could not get it up to java_1.6. So I ditched Leopard 10.5.8, and installed Snow Leopard 10.6.4, that got me up to 1.6, and now I am able to run the great app you made. Thank for the app,and all the support, to help me get it running. I left a post on your link.

Link to comment
Share on other sites

 Share

×
×
  • Create New...