GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes classpath problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath problem" Watch "classpath problem" New topic
Author

classpath problem

Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
Hi all,

I've been trying to execute a program for now 2 days and I'm not able to get my classpath correct. Here I'm writing the code as well as the commands that I'm giving. Kindly help.

Animal.java in C:\jdk\bin\corejava folder


and compiled using javac -d . Animal.java command from c:\jdk\bin\corejava prompt.

Bird.java in the same folder


Now I don't know what should I give in as a value of classpath so that my Bird.java file compiles. Everytime it will give me bad class file : Animal

Thanks


SCJP 1.5
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
If this is your class definition

,

then it must be placed in a directory named A.
Chris Beckey
Ranch Hand

Joined: Jun 09, 2006
Posts: 116

After compiling Animal you should end up with a directory "A" under the current directory and "Animal.class" in that. The classpath when compiling "Bird" should just include the current directory (not "A" or "A.Animal"). After compiling "Bird" there should be a "Bird.class" in the current directory.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
You are correct to use javac -d . Animal.java, which seems to work when I use Windows.
Try deleting the Animal.java file after you have compiled it into "A". I did. It worked (on Linux). No idea why you are getting this error.

Try Keith Lynn's suggestion and put Animal in directory A and back. Note you have to compile Animal from a command prompt in A before you can try compiling Bird from a command line in C:\jdk\bin\corejava.

BTW: You oughtn't to be keeping your exercises in a jdk\bin folder. Make yourself a "JavaPrograms" folder in MyDocuments or C drive or somewhere, so as to avoid confusion with the jdk files.
Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
Thanks....Thanks...Thanks all of you. Finally my program is running.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
We're only too pleased to help.
 
GeeCON Prague 2014
 
subject: classpath problem