This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes package compilation question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package compilation question" Watch "package compilation question" New topic
Author

package compilation question

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
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

Joined: Aug 06, 2004
Posts: 257
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

Joined: Nov 13, 2004
Posts: 66
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...


Have A Nice Day !!!
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
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

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
 
subject: package compilation question
 
Similar Threads
WA #1.....word association
A tool for producing Site Maps
JAXB 2 build error
Protected vs Default
Sentiment