Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
RE: How to change Java Home?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: How to change Java Home?



Thanks Pratik. Yes, I should've mentioned this as another approach in my post. The JAVA_HOME environment variable will work for Ant, but only because Ant happens to be written to look for it first before using "Java Home." But I meant for my question to be more generally about how to change "Java Home," and not specifically how to get Ant to work.

Ant just happens to provide a perfect example for this because it relies on "Java Home" and Apple ships it. So, for example, a vanilla Mac with only Leopard and Development Tools will fail to run Ant build scripts that require a 1.6 compiler. It's an example that can be easily reproduced without downloading weird stuff from third parties.

I understand I can force it to work, but none of the ways I understand to get it to work seem very elegant. That's why I feel like I'm missing something. The whole notion of "Java Home" just doesn't sit very well with me. The technical Q&A is written as if it's suggesting the right approach for developers. And the endorsement of Apple shipping Ant this way seems to echo that. However, with no ability to change it, I feel like maybe I misunderstood.

To get back to your response, I guess I consider the JAVA_HOME approach to be the best of a bad lot (more of a workaround than a hack). I'm sure it's somewhere in the official Ant documentation, so it's not a hack, but it's a workaround to the problem that there's no way to change "Java Home." Are you suggesting the Ant approach to the problem is the best approach?

Kirk


-----Original Message-----
From: Pratik Solanki [mailto:email@hidden]
Sent: Mon 6/23/2008 4:34 PM
To: Kirk Mattson
Cc: email@hidden
Subject: Re: How to change Java Home?

You should be able to set the JAVA_HOME environment variable to the java version you want. And ant will use that. Just set that variable in your .bashrc or equivalent file.

Pratik

On Jun 23, 2008, at 3:46 PM, Kirk Mattson wrote:


	Hi,
	OS X has the notion of a "Java Home" (/Library/Java/Home, or /System/Library/Frameworks/JavaVM.framework/Home) directory. As far as I can tell, the only official documentation on this concept is in a technical Q&A at http://developer.apple.com/qa/qa2001/qa1170.html. As with other operating systems, this directory is used as the root of a Java installation. This directory is controlled by the OS, and there doesn't appear to be any way to change it. I understand you can force changes to it manually, and previous posts ( for example http://lists.apple.com/archives/java-dev/2005/May/msg00154.html ) have suggested why that's a bad idea.

	Unfortunately, without changing it, you can't fully use some of the developer tools Apple ships with OS X, such as ant. For example, if you have a build script that has a javac target of 1.6, you will need to use the 1.6 version of javac. However, ant uses OS X's "Java Home" to get to javac. So, even on a Leopard machine that's current with the latest software updates and includes 1.6, this build script will fail. And I'm unable to figure out how to make it work without what I would consider hacks. For example, you could run the script through an IDE like Eclipse (and change your IDE's java settings), or you could use the bad idea in the first paragraph, but so far I haven't seen any real solutions to the problem. Am I missing something?

	Kirk

	PS: By the way, the notion of "Java Home" doesn't seem to have any relationship to either the Java runtime you use, or the JDK tools (such as javac) you use, as both of those are controlled by the Java Preferences app. If Ant were just calling "javac" from the command line instead of calling Java Home's javac (/System/Library/Frameworks/JavaVM.framework/Home/bin/javac), then I could make changes in the java preferences app, and tools like Ant would respect those changes.
	_______________________________________________
	Do not post admin requests to the list. They will be ignored.
	Java-dev mailing list      (email@hidden)
	Help/Unsubscribe/Update your Subscription:

	This email sent to email@hidden




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to change Java Home? (From: Kirk Mattson <email@hidden>)
 >Re: How to change Java Home? (From: Pratik Solanki <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.