• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package compilation question

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic