| Author |
K&B Exercise 1-1
|
vaibhav mishra
Ranch Hand
Joined: Jun 18, 2008
Posts: 168
|
|
I do as illustrated in code and the I got following my class path is set ok to directory which have food directory inside it and I placed Fruit class as instructed , can you please tell me where I am wrong
|
SCJP
|
 |
Keith Nagle
Ranch Hand
Joined: May 06, 2008
Posts: 65
|
|
Hi there. Can you give a little more information? Your classpath should be set to a directory that contains the directory food as a subdirectory.That's assuming you placed the class file in a directory called food. For example: package foo; public class MyClass{} Say I am in directory, C:\My Java and the source file MyClass.java is there, I would compile MyClass.java like so: (Note javac will look in the current directory for the source file, by default) javac -d . MyClass.java The -d flag specifies where you want to place the resulting class file. Here I specified '.' which means the current directory (C:\My Java) and it will also create the necessary directory 'foo' in which you will find the class file. Now to run the class file you have to make sure your class path contains an entry that will have the directory 'foo' as a subdirectory. Lets say we have the classpath set as a system variable like: C:\My Java;. this means, look in C:\My Java or the current directory. Note the ; delimiter that separates classpaths. OR You could specifiy the classpath on the command line and run the above class file like so: (Assume you are in the C:\My Java directory) C:\My Java>java -classpath . foo.MyClass Hope this helps. Best regards, K [ June 22, 2008: Message edited by: Keith Nagle ]
|
SCJP 5.0
|
 |
vaibhav mishra
Ranch Hand
Joined: Jun 18, 2008
Posts: 168
|
|
this is entry in my classpath and I placed my food file in and after copiling fruit file source I placed in directory food as instructed and then I give the command however I didn't use -d option
|
 |
Keith Nagle
Ranch Hand
Joined: May 06, 2008
Posts: 65
|
|
Originally posted by vaibhav katyayan: this is entry in my classpath and I placed my food file in and after copiling fruit file source I placed in directory food as instructed and then I give the command however I didn't use -d option
Hi again. Im looking at the exercise now and there is no food file. food represents the directory where the Fruit.class should reside. It's important that you remember that the classpath is evaluated from left to right. Try this: Go to the directory that you have the source file in i.e from the command line type: cd G:\Documents and Settings\vaibhav\Desktop\source Make sure teh Fruit.java is in there. Compile it like this: G:\Documents and Settings\vaibhav\Desktop\source>javac -d . Fruit.java This will create a sub directory in source that will be called food. AND it will have Fruit.class in there. So lets assume that Apple.java is in source also.To compile it, you will have to tell it where Fruit.class is, and you do that like this: G:\Documents and Settings\vaibhav\Desktop\source>javac -classpath . Apple.java That should then produce your class file. Note that since your system class path already contains a '.' which means "Current directory" supplying -classpath . at the command line is superfluous but im only saying this assuming that your classpath is correct. Try that and see how you get on. Best regards. [ June 22, 2008: Message edited by: Keith Nagle ]
|
 |
vaibhav mishra
Ranch Hand
Joined: Jun 18, 2008
Posts: 168
|
|
Thanks Keith, It seems that I totally misunderstood the problem but your explanation helps thanks again
|
 |
 |
|
|
subject: K&B Exercise 1-1
|
|
|