Re: How to set the classpath
When I have done command-line work in the past, I have taken care to set the system path to make the java compiler visible, but usually don't set or change the system classpath. Instead I've set it on the command line itself with the -cp command. Sometimes all it needs is a period . but sometimes it requires more.
Re: How to set the classpath
What is the -cp command and how does it work? Can you explain more? Thanks :)
Re: How to set the classpath
It's the same as the -classpath compiler or java option. You can read more here: Setting the classpath
Re: How to set the classpath
I read that and I don't understand what to put for C:> set CLASSPATH=classpath1;classpath2... What do I put for the classpath option? Do I put the directory to where the .class file is located?
Re: How to set the classpath
javac -cp path_to_classes FileName.java
Re: How to set the classpath
Okay, so I did that and I still keep getting the error:
Could not load or find main class MyFirstJavaProgram.java
What am I doing wrong? What is going on?
Re: How to set the classpath
Quote:
Okay, so I did that
What did you do? Copy and post the exact command and the resulting output as it appears at the command line.
Re: How to set the classpath
Okay:
cd Desktop
javac -cp path_to_classes MyFirstJavaProgram.java
java -cp path_to_classes MyFirstJavaProgram.java
Even if I take out the path_to_classes I still get the error as well.
Re: How to set the classpath
Please note that you did not in fact copy and post the output from the commands.
The previous suggestion was not that you use literally "path_to_classes" in the command. Rather the intent was that you use the actual classpath that you intend for the commands. Supposing that MyFirstJavaProgram.java is a file on your desktop, you might try something like:
Code:
cd Desktop
javac -cp . MyFirstJavaProgram.java
java -cp . MyFirstJavaProgram
Mind the dot! It stands for "the current directory" and will serve for "path_to_classes" in this simple case. Notice, too, that while the compiler command (javac) expects a file to compile, the runtime (java) expects the name of a class which does not have a dot in it. MyFirstJavaProgram.java is the name of the file, MyFirstJavaProgram is the name of the class.
If you get stuck do copy and post the output from the command line. The contents of the MyFirstJavaProgram.java file also make a difference (the class being defined should not be declared to be in a package or that changes things, also it must have a well defined main() method.) If you are in any doubt post the contents of that file as well.