Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rating: Thread Rating: 13 votes, 4.85 average. Display Modes
Old 11-16-2005, 04:05 AM   #1
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
Java 5 (aka Java 1.5) for Tiger

Apple has released a Java update- it is available on Software Update as well as being available for download via: http://docs.info.apple.com/article.html?artnum=301073
But note that this update is only available if you are running Tiger (OS X 10.4) - Apple does not intend to release this version of Java for previous versions of OS X.

This update installs version 5.0 of "Java 2 Platform Standard Edition" (J2SE) - i.e. the standard Java runtime that can be used by Java applets and Java applications.
The version numbers are rather confusing and that is one of the things I hope to clear up in this post. (I'm trying to forestall some inevitable questions.)

Version numbering confusion
The previous version of Java that was supplied with OS X was 1.4.2
In comparison to that, this latest version is version 1.5.0
But for marketing purposes (to emphasize the changes), Sun (the originators of Java) has decided to refer to this as version 5.0
So you will hear of people referring to Java 1.5 and Java 5 but these are both referring to the same thing.

Java 1.4 remains the default
One thing that is different about this update (as compared to previous Java updates in OS X) is that it doesn't replace the previous version of Java.
In fact, installing this update will result in no change at all in the behaviour of your Java programs until either you take some action to select a preference for Java 5 (see below) or the developers of those Java programs make a change so that their programs request Java 5.

In other words, installing this Java update merely installs the Java 5 software (runtime and associated support utilities) - it does not affect the currently installed Java 1.4 software. This is different from the previous transition from Java 1.3 to Java 1.4 where the update left the existing Java 1.3 software in place, but changed the system so that Java 1.4 was the default. This latest update leaves the Java 1.4 (and 1.3) software in place but it doesn't change the default. The default version of Java is still 1.4

The reason why Apple left the default Java version as 1.4 is that some of the changes between 1.4 and 5.0 might break some Java applets or applications. Thus it should be quite safe to install this update since the default Java environment is unchanged.

Why install this update?
There are many improvements in Java 5 and it is definitely a good idea to install this update even though (as I said above) it likely won't initially change anything in your Java experience. Some of the new features in Java 5 make it easier for programmers to develop Java programs and so you can expect that more and more Java programs will require this version of Java. For applets and "Java Web Start" applications (i.e. programs that are downloaded just before running them), developers can request that Java 5 be used if it is available. So you may find that some of these type of Java programs will see improvements right away if their developers have implemented them to request Java 5.

Specifying use of Java 5 for applets and "Java Web Start" apps
This update installs some new utility apps in the folder "/Applications/Utilities/Java/J2SE 5.0". The most important is the "Java Preferences" app. This utility allows you to specify what version of Java you want used for applets and for "Java Web Start" applications. As I said above, the default version used for these does not get changed when you install this update - the default version remains at 1.4.2
If you want to try using Java 5 for applets and/or "Java Web Start" applications, you can switch the default for these by using the "Java Preferences" app.
In some cases, this may give much better results due to bug fixes and performance improvements in Java 5 versus Java 1.4
If something doesn't work properly, you can always just switch the default back to Java 1.4

Version of Java used for installed Java applications
It is important to note that the default version of Java for Java applications (that have previously been downloaded and installed on your hard drive) does not change with this update.
Furthermore, it is not always possible to change the version of Java that is used by these sorts of apps (as opposed to applets in a browser or "Java Web Start" applications) by using the "Java Preferences" app.

For Java applications that have been packaged into OS X application bundles (with a ".app" suffix), the developer will have indicated what version(s) of Java are to be used for that app by specifying this in the Info.plist file that is a part of the application bundle. Which version of Java gets used for these apps depends on what the developer has specified and what you specify via the "Java Application Runtime Settings" section in the "Java Preferences" app. This is explained in the "versioning" section of Apple's release notes (intended for developers).

If the developer has specified that the app is to be run on Java 1.4, then it doesn't matter what you set in the "Java Preferences" app. The developers of these Java applications can of course supply new versions of the apps that make use of Java 5.

For Java applications that are supplied as a ".jar" file, the settings in the "Java Application Runtime Settings" section of the "Java Preferences" app will determine which Java version is used when you double-click the ".jar" file in Finder. If you drag the "J2SE 5.0" to the top of the list in the "Java Application Runtime Settings", then a double-clickable jar application will use Java 5. You can test this with the small Java application "JavaVersionDialog.jar" that I attach at the bottom of this post. (It is a ".zip" file due to limitations of this forum, but double-clicking it in Finder will unzip it to reveal the ".jar" file.)

It is also possible (but not recommended!) to change things in the /System area of OS X (changing symbolic links, etc) so that the default version is Java 5.

Some Java applications (e.g. development tools like "XCode" and "Eclipse") will provide user-settable preferences to specify the Java version that is to be used. Again, note that it is strongly recommended to use these per-application settings instead of making system-wide modifications in the /System area of OS X.

Changing the version of Java used for applications started from the command-line
For any Java application that is started from the command-line (in a Terminal window), it is simple to change the environment so that Java 5 will be used without having to make any changes in the /System area.
This is particularly relevant for Java developers but note that any Java application that is supplied in the form of a ".jar" file (which is double-clickable in Finder) can be started from the command-line by means of the following command:
java -jar name_of_jar_file

To change the environment so that Java 5 is used for Java applications started from the command-line, you can use the Bash functions supplied by Shawn Erickson in this mailing list message:
http://lists.apple.com/archives/Java.../msg00506.html
For example, I saved these functions in a file called "java_functions_bashrc" in my home folder. Any time I want to run an application from the command-line using Java 5, I run the following command:
source java_functions_bashrc
This installs those functions into the Bash environment of my current window. (If I wanted these functions to be available in all windows, I could put them into my ~/.profile file. For more info on Bash functions and shell configuration files, see this Unix FAQ)
But doing that hasn't yet changed the default Java version.
To change to use Java 5 for the applications that I will start from that Terminal window, I then run the command:
setJava 1.5
All Java applications that I start from then on in that Terminal window will use Java 1.5 (= Java 5.0)
To get back to the previous default (Java 1.4), I would run the command:
unsetJava
Or I could just quit that Terminal window and start a new one when needed - the changes from the 'setJava' function do not affect anything outside that one Terminal window.
The function 'listJava' lists the available versions of Java.

Independent of these functions, you can always find out what version of Java will be used for a command-line application by running the command:
java -version
Note that the version number shown by this command is the "engineering" number (e.g. 1.5.0_05) - as opposed to the "marketing" number (e.g. 5.0)

Summary:
1) The update (which is only available on Tiger) installs Java 5 (which is also known as Java 1.5)

2) The default version of Java remains as Java 1.4 even after the update. Thus it should be quite safe to install this update since by default it makes no change to the Java environment.

3) You can change the version of Java to be used by web-based Java programs (applets and "Java Web Start" applications) and Java applications that have been packaged as a ".app" bundle by using the new "Java Preferences" app that is in the "Java/J2SE 5.0" folder under the /Applications/Utilities folder. This also works for Java apps that are supplied as ".jar" files if you double-click them in Finder.

4) Contrary to what you may have read elsewhere, you should not modify anything (e.g. symbolic links) in the /System area of OS X to change the default to be Java 5.
Instead you should make use of the per-application preferences provided by some applications,
or wait for new versions of applications where the application developers have changed them to use Java 5 by default,
or make use of the Bash functions mentioned above to change the default for applications started from the command-line.
Attached Files
File Type: zip JavaVersionDialog.zip (995 Bytes, 1720 views)
File Type: txt java_functions_bashrc.txt (2.9 KB, 1931 views)

Last edited by hayne; 01-27-2006 at 09:34 AM. Reason: corrected misstatement re version used for double-clicked jars; attached java_functions_bashrc file
hayne is offline   Reply With Quote
Old 11-16-2005, 10:34 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
For those that are interested, here is the source code for the small test application I posted above as a ".jar" file:
Code:
import javax.swing.*;

public class JavaVersionDialog
{
    public static void main(String[] args)
    {
        String version = System.getProperty("java.version");
        String versionInfo = "Java version: " + version;
        System.out.println(versionInfo);
 
        JOptionPane.showMessageDialog(null,
                                      versionInfo,
                                      "Java Version",
                                      JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
    }
}
hayne is offline   Reply With Quote
Old 12-12-2005, 12:45 PM   #3
stephanterning
Registered User
 
Join Date: Dec 2005
Posts: 1
What is the right way to make deamons launching before login to use Java 5.0? In this case I'm trying to get Tomcat to use Java 5.0.
stephanterning is offline   Reply With Quote
Old 12-12-2005, 01:55 PM   #4
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
Quote:
Originally Posted by stephanterning
What is the right way to make deamons launching before login to use Java 5.0? In this case I'm trying to get Tomcat to use Java 5.0.

Although I don't have any experience with doing this, I would think it is a simple matter of setting the PATH to point to the desired version of Java - as is done via the Bash functions I linked to above. You can probably just set the PATH in your Tomcat startup script, but there might be other environment variables (e.g. JAVA_HOME) that you need to set as well - read the Tomcat docs to find out.
hayne is offline   Reply With Quote
Old 12-14-2005, 02:10 PM   #5
closer
Triple-A Player
 
Join Date: Sep 2003
Location: ontario
Posts: 69
Java Web Portal fix?

in the last year and a bit we've had some major problems accessing web sites using Safari (or any other browser) that rely somehow on the SUN version of Java that uses Portals (content inside the portals would not show up).. would you think that this newest version 1.5 may fix this?... I don't want to upgrade our current systems (10.3.8) to Tiger if it won't fix it... cuz nothing else is broken right now... if it fixed the portal prob though it would be worth the time and money spent ungrading
closer is offline   Reply With Quote
Old 12-14-2005, 06:29 PM   #6
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
Quote:
Originally Posted by closer
in the last year and a bit we've had some major problems accessing web sites using Safari (or any other browser) that rely somehow on the SUN version of Java that uses Portals (content inside the portals would not show up).. would you think that this newest version 1.5 may fix this?... I don't want to upgrade our current systems (10.3.8) to Tiger if it won't fix it

I don't know anything about this Sun Portal problem.
You should just find a Mac with Tiger installed on it to try it yourself.
Or tell us an example URL so we can try it. (Be sure to describe exactly what part doesn't work for you)
hayne is offline   Reply With Quote
Old 04-20-2006, 09:31 PM   #7
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
Apple has now released J2SE 5.0 Release 4 (for Tiger - OS X 10.4) which makes Java 5 the default. This will appear in Software Update for all users on Tiger.

Here's the release notes: http://developer.apple.com/releaseno...4RN/index.html

See this Apple doc about possible incompatibilities: http://developer.apple.com/qa/qa2006/qa1474.html
__________________
hayne.net/macosx.html

Last edited by hayne; 04-21-2006 at 04:18 PM.
hayne is offline   Reply With Quote
Old 07-08-2006, 02:37 PM   #8
Keld
Prospect
 
Join Date: Jul 2006
Posts: 4
Thank you, thank you for this thread. It saved me! Unfortunately 10.4.7 *still* doesn't implement Java 1.5 as the default in the terminal. At least not for me.

Cheers!
Keld is offline   Reply With Quote
Old 07-08-2006, 06:57 PM   #9
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 32,437
Quote:
Originally Posted by Keld
Unfortunately 10.4.7 *still* doesn't implement Java 1.5 as the default in the terminal. At least not for me.

Then I think you must have customized something.
I have a factory-standard Java installation on my 10.4.7 iBook G4 and Java 1.5 is the default for me:
Code:
% java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-112)
Java HotSpot(TM) Client VM (build 1.5.0_06-64, mixed mode)
Check what you have in your shell "dot" files (see this Unix FAQ)
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 07-16-2006, 07:42 PM   #10
Keld
Prospect
 
Join Date: Jul 2006
Posts: 4
Well it turns out that I didn't have *all* of the latest and greatest of everything. I tried to upgrade things in a piecemeal fashion, and in the end I just updated via software update and got the latest java version. Things work now.

Apple info would suggest that other methods work, but that wasn't my experience. Thanks for the help.
Keld is offline   Reply With Quote
Old 08-24-2006, 10:10 AM   #11
JV Designs
Prospect
 
Join Date: May 2006
Posts: 3
Just wanted to say thank you for this helpful and informational post. You cleared up a lot of things for me. Take care.
JV Designs is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 03:09 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.