aspose file tools*
The moose likes Cattle Drive and the fly likes Lost on the classpath! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Lost on the classpath!" Watch "Lost on the classpath!" New topic
Author

Lost on the classpath!

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
I need some help understanding this classpath thing. Looking ahead at OOP1, I see instructions telling us we have to download a .jar file, and then something about the classpath stating that if you write your programs in C:\java ( and I do ) then the .jar files could be put in a folder in C:\java called somenameorother and the classpath would look like:
C:\java;C:\java\somenameorother

what exactly is going on in this classpath statement? Why the semi-colon in the middle? I never really had to learn any DOS commands, so I get lost over the simplest things! Does the above mean that the files will be found in C:\java and C:\java\somenameorother? Can classpath be that simple? Would file location be another way to say classpath, or I am missing some occult meaning? Another sleepless night..................
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
The semicolon is a separator. The classpath is to tell the program you are running (javac I this case) where to look.
I'm not sure of the exact sequence (I'll check today & post correct later if I'm wrong), but I think it goes something like this, first the directory your program is in, then the first directory in the classpath, then the next etc.
Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351
The CLASSPATH tells the Java compiler where to look for Classes. It contains file locations (pathnames). The format to define it is based on the DOS methodology for creating an environment variable on a Windows PC. I'm not sure what the format would be on the UNIX or MacOS operating systems, but the idea is the same.
javac search order for Classes:

    1. The current directory.
    2. $JAVA/classes (where $JAVA is the parent location of the Java compiler, interpreter and other components).
    3. $JAVA/classes.zip. This is a .zip file rather than a directory. Java knows how to extract class library components from a .zip file.
    4. Any additional directories assigned to the environment variable (CLASSPATH)

    Just Java 2, Peter van der Linden, discusses this topic on page 223.
    Michael
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
I knew I saw it somewhere thanks saves me looking
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
CLASSPATH is also discussed briefly on the first cattle drive page.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Still don't get it. How do I determine what my classpath is? I created a folder on my C drive ( called the root (?) ) named java. I put my JDK in this folder, and this is where I save all of my java and class files for the cattle drive. So what would my classpath be if I downloaded the necessary .jar files into
C:\java? For some reason this is not making any sense to me. If I download a .jar file and place it in C:\java, will the compiler be able to locate it without any specific instructions?
When I installed the JDK it worked without my having to monkey with any of this stuff!
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Carol at the dos prompt type in set and you will see a list all you settings.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Thanks, I'll do that!
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Okay, for my PATH I have the following:
PATH=C:\WINDOWS;c:\windows;c:\windows\COMMAND;C:\JAVA\BIN
So what does all that mean? I don't have any experience with DOS commands, so this is Greek to me! And I don't speak Greek!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Definition: A class path is an ordered list of directories or *.zip or *.jar files in which to search for class files.

Therefore, if you want a *.jar file in your classpath, you have to explicitly put it there, separating it from the previous classpath with a semicolon.

For example,
CLASSPATH=C:\Java;C:\Java\example.zip;C:\Java\example2.jar
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
So if I download the necessary.jar files and put them in my
C:\java folder which is where I keep all of my java files, then my CLASSPATH would look like:
C:\java;C:\java\necessary.jar
In order for the compiler to find the class files that are located in the .jar file?
Sorry to be so dense, but there is something about this which is keeping me from feeling like I understand what everyone is talking about.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10

So if I download the necessary.jar files and put them in my
C:\java folder which is where I keep all of my java files, then my CLASSPATH would look like:
C:\java;C:\java\necessary.jar
In order for the compiler to find the class files that are located in the .jar file?

Exactly
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Depending on your operating system, UNIX or e.g. Windows NT,
you are able to set your CLASSPATH environment variable.
UNIX uses e.g. '.profile' (if using K-shell) (for C-shell '.cshrc', and maybe other shell's use other files to execute and set environment variables first ['.bashrc']).
On windows NT I right-click 'My computer' (on the desktop) and open the tabpage for Environment, then I goto 'CLASSPATH' (and click) and then I can add or change the CLASSPATH (don't forget to "set" it too !).
And as is mentioned above the semicolon is a necessary separator if you have to point to different jar-files or directories.
 
 
subject: Lost on the classpath!