HERE is a page I put together on this topic. See if it helps.
I don't set the PATH or CLASSPATH for Java programs in the control panel, but as part of a batch file for each program or command window session. I keep several JREs and JDKs on my system and I can set these variables for just the environment I need for each program. For example, my work stuff has to run under 1.3 and my fun stuff runs under 1.5.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
[Stan]: I don't set the PATH or CLASSPATH for Java programs in the control panel, but as part of a batch file for each program or command window session.
For people wishing to follow Tony's advice (which is also good, but incomplete), you would probably benefit from the following tip: instead of setting the CLASSPATH, you can run java or javac using the -classpath or -cp options. This is essentially equivalent to setting the CLASSPATH variable, except it's only set for that one particular invocation of the javac or java command. Which is usually a good thing. The problem with setting the CLASSPATH via the control panel (or in a loging script) is that there's only one CLASSPATH on the machine (or rather, one per user, maybe), and when you change it, you're changing it for all programs that use it. Which has a good chance of breaking them -- especially if you're a beginner.
Other common alternatives to setting CLASSPATH or using the -cp options are:
let an IDE take care of it for you (the IDE may well use -cp behing the scenes)
use java's -jar option and make sure all necessary classes are in the jar
use a war or ear file and let a web server or app server take care of finding the classes
create a custom class loader to find classes by some other method
Since this is the Beginner forum, ignore those last three suggestions. I recommend using -cp, or setting CLASSPATH in a batch file as Stan suggests (so it's valid only for the current session), or using an IDE. Well, the -jar option is not bad either, but creating the jar is a little bit more advanced. [ December 02, 2005: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Joined: Nov 27, 2005
I solved the problem guys!Thanks to Stan James. All i did was type the following before compiling \ running:
Now only if I could figure out why it worked. And how to automate it so that I need not type it each time. Don't I sound lazy?
I too is very lazy in typing commands in the prompt again and again. what i do is make a file with .bat say lazy.batas extension with all the commands you want to execute and in the command prompt go to the place where lazy.bat sits and just hit lazy.bat....its done.
First, why this worked: You're setting the classpath to the current directory (".") here, so by doing this, Java will look for classes in the directory that you're running the command from.
To avoid having to type this every time: Make sure that you do not have a CLASSPATH environment variable set at all. If it's not set, Java will by default use the current directory.
Try this (Windows XP): Click on Start, move your mouse cursor to My Computer, right-click on it and choose Properties in the popup menu. Now go to the Advanced tab and click the button Environment Variables in the bottom of the dialog box. Make sure that there is no CLASSPATH variable in either the User Variables or System Variables list (if there is, click it and press the Delete button). Click OK to close the dialog boxes.
Open a new command prompt and type: echo %classpath%
It should respond with: %classpath% which means the classpath environment variable is not set.