File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to get this package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get this package?" Watch "How to get this package?" New topic

How to get this package?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
I was making two different classes like this:
public class dbconn
package db.dbconnect;
//**** and rest of codes here

another is:
public class testData
import db.dbconnect.*;
//**** and rest of codes here
now both java files are in same directory. I am also setting the classpath for current director by giving following command:
set classpath=.;%classpath%
if i echo the classpath it shows the current directory too. If I try to compile the first one it gets compile easily but now if i try to compile the second one it gives error that package not found.
but strangely if i give packe like:
import db.dbconnect.dbconn;
it accepts. why?
Isn't first style also Ok?
Pl give your comments.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
First of all the package statement needs to be the first executable statement of your code.
After you compile the first class, you need to create directory structure that mimics the package path and move the class there.
If your class B is in C:\myprogram folder and you are importing db.dbconnect, there needs to be a dirtectory db in c:\myprogram. The db directory should contain a dbconenct directory which should contain the class you are trying to import.
Hope this helps
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks Shivaji for your comments.
But the strange thing is that I am using command javac -d . dbconn.javaThis itself gives that directory structre which ever is needed.(Though I have also confirmed after physically looking at this and it is there) but still the problem remains same.
I agree. Here's the link:
subject: How to get this package?
It's not a secret anymore!