Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath problem

 
Asha Pathik
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is your class definition

,

then it must be placed in a directory named A.
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks....Thanks...Thanks all of you. Finally my program is running.
 
Campbell Ritchie
Sheriff
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're only too pleased to help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic