The moose likes Beginning Java and the fly likes set classpath= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "set classpath=" Watch "set classpath=" New topic

set classpath=

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. I've been doing java for a few months now, and I am finally going to try and nip this problem in the bud.
Whenever I first open my DOS prompt, why do I have to key 'set classpath=' before my java program will compile? It compiles fine if just using one class, but if using multiple classes, it can't find them unless I key 'set classpath=' first.
I have c:/jdk1.3/bin in my CLASSPATH and Path system variables. I am running on W2K.
Can anyone help??
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Well, I don't know if this will answer your question, but:
If I remember correctly, since jdk1.3 the SET CLASSPATH which in the past was set in your enviornment variables is no longer a necessity. However, that is only for classes that are part of the jdk package.
What you might want to do is go ahead and include the SET CLASSPATH= in your environment varibles as you did with your path to the bin dir. That may help you locate your problem. You may want to try and re-install the jdk. Also, make sure when you are talking about "multiple classes" you are using classes that are packaged with the jdk and not other classes that you have created yourself and/or downloaded as thrid party packages. When using those types of classes/packages, you will need to set your classpath either at the time of compile or in your environment variables.
Hope that makes since and helps a little.

GenRocket - Experts at Building Test Data
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
You need to make sure that the directory that holds YOUR compiled classes is in the Classpath. When you compile more than one class the system is not finding the first class when compiling the second. You also need to make sure that the directory that holds SUNs classes is in the directory. They are in the \lib subdirectory. In addition it is a good practice to include a dot reference in your classpath. That will mean that any class files that are sitting in whatever directory that you happen to be sitting in will also be found. (Just in case you are not sitting in the directory that you included as your working directory).
So your classpath should include:
classpath = .;c:/jdk1.3/lib;c:/pathToYourWorkingDirectory;
In addition, you can set this in the autoexec.bat if you don't want to do it by hand every time. Or you can create a bat file to set it for you to prevent having to retype all this all the time.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

But since you're using Win2k, you won't use autoexec.bat, but rather, Right-click 'My Computer', Properties, Advanced, Environment Variables.

You can find CLASSPATH, or make a new one if it's not already there.

I'd put it in the System variables section, so you can use it no matter who you are logged in as.
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
I have a simple class and I've set my classpath to the directory the class file sits in. I have no packages and I set the classpath through the environment tab of the System icon in Control Panel (Win NT). How come my application still doesn't see the class?
The call to this class is set into the file. Any java application is supposed to trigger whatever class resides here.
I agree. Here's the link:
subject: set classpath=
It's not a secret anymore!