Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PATH and CLASSPATH

 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Terminal.app, 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:

echo {CLASSPATH}

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
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sunil choudhary
Ranch Hand
Posts: 144
Java Redhat Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, OS X is a unix variant. Look up the term "Darwin" for more details.
 
sunil choudhary
Ranch Hand
Posts: 144
Java Redhat Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sherrif,
I was not aware of Darwin at all. Actually i am amazed i did not knew.
 
Andrew Zielinski
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/TextEdit.app -/.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
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file you seek is .bash_profile
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic