my dog learned polymorphism
The moose likes Beginning Java and the fly likes Typical packages problem!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Typical packages problem!!!!" Watch "Typical packages problem!!!!" New topic

Typical packages problem!!!!

Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
can someone please help?
i have java files arranged like this:
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
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
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

SCJP 1.4
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
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.

For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
Sri Addanki
Ranch Hand

Joined: Apr 27, 2001
Posts: 195
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,
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
Great! Glad we were able to help.
I agree. Here's the link:
subject: Typical packages problem!!!!
jQuery in Action, 3rd edition