• 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

Typical packages problem!!!!

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
can someone please help?
i have java files arranged like this:
c:\lax\prog\sun\ui\*.java
c:\lax\prog\sun\db\*.java
java classes in the package UI need java classes in the package DB.
And my typical java class file, in package UI looks like this:

package sun.ui
import sun.db.*;
class XX{}
There's a compile time error saying can't find sun.db package and can't resolve symbol.....
where am i missing???
my javac command line option is:
c:\javac -classpath c:\lax\prog\sun\db c:\lax\prog\sun\ui\*.java
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if your package is sun.ui, then your classpath needs to be set to allow the JVM to find your package, starting with "sun". You're going too deep into the package hierarchy when you define your classpath. The JVM just needs to look inside \lax\prog to find your packages, so your classpath should be just "c:\lax\prog "
And your javac call should be:
c:\javac -classpath c:\lax\prog c:\lax\prog\sun\ui\*.java
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your command line should be this:

This is saying "Compile all the java files in c:\lax\prog\sun\db\ and c:\lax\prog\sun\ui\ directories AND when you do that be sure to use c:\lax\prog\ as the classpath.
Remember, when a file is in a package the compiler and JVM wil automatically add that directory structure to the class path. So if you have your classpath set to c:\lax\prog\ and you have a file that is in the package sun\db then the compiler will actually look for that file in c:\lax\prog\sun\db WITHOUT you having to specify the classpath for each file. That's why you only have to specify one directory for your classpath.
The way you had it the compiler was actually looking for your file in c:\lax\prog\sun\db\sun\db
Hope it helps.
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob and Greg,
Thanks alot!!!
That was a fast reply.
Its working fine!!!
yes what u've said is right. I need to put c:\lax\prog after javac -classpath.
Thanks again,
Sri
 
Greg Brouelette
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! Glad we were able to help.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic