File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mac OS and the fly likes PATH and CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "PATH and CLASSPATH" Watch "PATH and CLASSPATH" New topic


Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

I've read in other forums, here in the javaranch, that many people have problems setting their environment variables: PATH and CLASSPATH.

It seems that when I ran the Mac OS X installer for Java 5.0 that I downloded from:

Apple's Java Web-Site

That the Java 5.0 installer automatically set my PATH variable to find the 5.0 version of Java. I confirmed this by trying the command:

java -version

All of my Java command-line commands seem to work (that is java and javac both work).

The command "java -version" returned a version number of 1.5.0_06 which sounds good to me, but when I type the command:

echo {PATH}

into the, the string "{PATH}" is displayed in my Terminal window instead of the search path used to lookup command-line commands.

Also, I plan not to use CLASSPATH, because it seems like it is a pain-in-the-neck and a source of many problems, but I still want to see what it is set to. When I type the command:


the string "{CLASSPATH}" is displayed in my Terminal window.

I believe that I'm using the default shell, which is bash, right?

I don't understand why I can't view the environment variables: PATH and CLASSPATH.

-- Kaydell
[ December 06, 2006: Message edited by: Kaydell Leavitt ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

Yes, the default shell for Mac OS 10.4 is bash.

Because of the way Java is installed on a Mac, the PATH variable is not something you should have to worry about. If you type "echo $PATH" you should see the value of your PATH. The default is as follows (with values separated by colons -- not semicolons)...

Now, if you list the contents of "/usr/bin" (using the -l flag), you should see that "java" and "javac" are both links to System Frameworks. In particular, they end up under /System/Library/Frameworks/JavaVM.Framework/Versions/CurrentJDK...

Note that "CurrentJDK" is an alias for one of the Java versions installed on your machine. In this case, it's aliasing the 1.5.0 folder that's also under Versions. Under that folder is another folder called "Commands," which is where you will find the java and javac executables.

The Key Concept is this: If you're looking to change your version of Java on a Mac, do not change your PATH. Instead, change the CurrentJDK and/or Current alias in the Framework.
[ December 06, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Thanks. Me too just got a Mac pro.
thanks for a valuable starting point.

So basically Mac Os X is very similar to the unix O/S
i have been working on Unix and PCs and must admit this change to Mac was a leap of faith. Feels i am in safe hands

"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60780

Yes, OS X is a unix variant. Look up the term "Darwin" for more details.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Thanks Sherrif,
I was not aware of Darwin at all. Actually i am amazed i did not knew.
Andrew Zielinski

Joined: Apr 09, 2009
Posts: 1
I'm new to Java and at the very beginning of my learning.

Of course, it took all of 45 minutes in my first class to discover that I need to modify the mysterious classpath.

My professor tells me to edit the .profile or .cshrc file but I can't find any of these on my Mac.

Then, I watched a video on the internet that said the following command would help edit the classpath:
open /Applications/ -/.profile

Is it possible that my Mac doesn't have such a file?

The reason for all this is that I need to add the core java package to my classpath.

Can someone please help?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60780

The file you seek is .bash_profile
I agree. Here's the link:
subject: PATH and CLASSPATH
Similar Threads
CLASSPATH question in Linux SuSE
Servlet Compiling Problems
Path and Classpath
setting Linux Java environment
How do I see my classpath?