• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package compilation question

 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. If anybody has a minute...

If I have two java files, say, Spider and Ant, and they are in the same package, shouldn't Ant be able to recognize a reference to Spider if Spider is compiled first? I keep getting "cannot find symbol class : class Spider" when compiling Ant. Spider has public accessibility. Thank you...
[ February 16, 2005: Message edited by: Tom Griffith ]
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. Another note, both java files contain this statement and are located in the insects subdirectory...

package insects;

I've added this import statement to Ant...meaning it should see ~all classes~ within the insects package, right?...

import insects.*

but I still get the same "cannot find symbol: class Spider" error...

thank you again...
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to the command prompt and compile

c:\insects>javac -d . Spider.java
c:\insects>javac -d . Ant.java

now execute

c:\insects>java insects.Ant

I think this should work...

Correct me if i am wrong...
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi prasanth. Thank you very much for that. It took the argument. It seems to me that the definition given for the -d argument at the command prompt when an error is generated..."-d - specifying where to place generated class files" isn't very telling as opposed to "specifying where to ~read~ generated class files"...

I also though the pakage definition inside the java file would handle the ~where~, but I guess that is for runtime...
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably don't have the necessary directory in your classpath.

See How to set classpath FAQ.

e.g. if Ant.java and Ant.class in package insect are in c:\src\insect ,then add c:\src to classpath. javac/java need to know where to start looking for classes.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom Griffith:
Hi prasanth. Thank you very much for that. It took the argument. It seems to me that the definition given for the -d argument at the command prompt when an error is generated..."-d - specifying where to place generated class files" isn't very telling as opposed to "specifying where to ~read~ generated class files"...

I also though the pakage definition inside the java file would handle the ~where~, but I guess that is for runtime...


As noted by Carol above, the classpath indicates where to *read* generated class files. You can set the classpath either through the CLASSPATH system variable or by using the -cp (or sometimes -classpath) command line option for java and javac.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic