-
CLASSPATH
I'm running JDK1.2.2. I set the CLASSPATH in my autoexec.bat file so that the folder where I planned on keeping my .java and .class files. It seems like it partially worked, as when I do a compile from the DOS prompt, I don't have to specify the location of the .java files. However, I was expecting that the .class file would be put back in to that same directory. It did not. It ended up in the c:\ root directory.
Also, when I tried to execute the .class file, I got an error that it could not find the class. (when I removed the CLASSPATH the program executed properly).
Thanks in advance for any assistance!
Lonnie
[email protected]
-
Re: CLASSPATH
> However, I was expecting that the .class file would be put back in to that same directory. It
> did not. It ended up in the c:\ root directory.
javac.exe creates the class file from where you are invoking it. In this case , you
are compiling the java file from the root directory. There is a command line option in
javac.
try ,
c:\> javac -d < c:\mydirectory> myjavafile.java
now you will get the class file under c:\mydirectory.
poochi
-
Re: CLASSPATH
Also ensure that when u r setting the classpath, give class path of default java classfiles also.
So the CLASSPATH may look similar to...
CLASSPATH=.;C:\jdk1.2\jre\lib\rt.jar;<your_path>
If u specify only class path of only ur files, u might get same error as java won't find the default classes.
- UnicMan
http://members.tripod.com/unicman
-
Re: CLASSPATH
When you compile the java classes I guess you did it at the c:\> prompt. The compiled classes (.class) are stored in the dir displayed by the prompt. By compilation I enter the destination dir (where .java files stored) and do the compilation there.
Someday I encountered problems like this. If you set the CLASSPATH it overrides the existing ones and you should specify the source of the original Java classes (i.e. c:\jdk1.2.2.\lib\classes.zip).
Other problem can be (I think not in this case) that you specify a package at the beginning of class (i.e. package MyPack). In this case you should execute .class like this: java MyPack.MyClass.
-
Re: CLASSPATH
Hello Lonnie,
I experienced similar frustration even after setting up the CLASSPATH environment variable at first. I downloaded JDK1.2.2 in a personal directory but the /bin directory and the standard library etc. of the Java language needed to be accessible. So I read the 4DOS help screen and found stuff on ALIASES so that I could execute command line commands without having to be in the bin directory. In short I opened 4DOS and created several aliases by typing in the following:
***********************************************
C:\> alias java=C:\DanielLyle\JavaDevelopment\bin\java.exe
C:\> alias javac=C:\DanielLyle\JavaDevelopment\bin\javac.exe
C:\> alias appletviewer=C:\DanielLyle\JavaDevelopment\bin\appletviewer.exe
C:\> alias gapples=cd C:\DanielLyle\JavaDevelopment\danscode
**************************************************
then I saved these to an alias.lst file by typing in
******************
C:\> alias > alias.lst
******************
then whenever I want to compile and run a Java source file -- called TestProgram1.java for instance, I open 4DOS
type
******************
C:\> alias /r alias.lst
******************
to reload my saved aliases into the 4DOS environment
and then type
************
C:\> gapples
************
to bring up the directory I have chosen to save my work in -- in this case the 'danscode' directory.
Note the power of aliases -- they are effectively short-hand directory accessing statements so that you can change directories in 4DOS and still execute files in
subdirectories as if they were global commands.
Now I can type in
*********************
C:\> javac TestProgram1.java
*********************
assuming I have a TestProgram1.java source code written in proper Java.
And finally I can run it with either the appletviewer or java commands depending if I am running an applet or an application (applets require an additional html file).
For more complicated and complex projects, I would read up on using the Package statement to package various class files together (in a directory with the same name as the package).
Hope this helps -- sorry if I got too detailed (not trying to insult your intelligence, just being thorough to help you see what I did).