Accessing a Package that is not on my hard-drive

Hi,

I am writing a class that is saved on my hard-drive. But in the beginning I need to 'import' classes from a package that is not on my hard drive. Let's say it is on a CD.

How should I be using the import statement to import the classes in this way? Does this have anything to do with setting up the PATH or CLASSPATH variables?

Thanks!

[369 byte] By [ahujava] at [2007-10-3 3:30:19]
# 1

The import statements in the .java files don't care where the classes to be imported reside.

You just have to set up your CLASSPATH (preferably on the command line, not as an environment variable) to include the other drives.

If you are in Windows and you need to import something from the CD Drive D:, you'll need a classpath like:

java -cp D:\someDir;C:\someOtherDir\anotherDir\some.jar MyClassToRun

MLRona at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...
# 2

Suppose if the class that I want to import is at the following location:

D:\dir1\dir2\dir3\java\com\dir4\dir5\class.java

In class.java the first line is:

package com.dir4.dir5;

Then at the command prompt I set the classpath to be:

set CLASSPATH=D:\dir1\dir2\dir3\java\com\dir4\dir5\class.java

It does not work. I have also tried:

set CLASSPATH=D:\dir1\dir2\dir3\java\

Any suggestions? Thanks!

ahujava at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...
# 3

> Suppose if the class that I want to import is at the

> following location:

> D:\dir1\dir2\dir3\java\com\dir4\dir5\class.java

>

> In class.java the first line is:

> package com.dir4.dir5;

>

> Then at the command prompt I set the classpath to be:

> set CLASSPATH=D:\dir1\dir2\dir3\java\com\dir4\dir5\class.java

That one is definitely wrong.

> It does not work. I have also tried:

> set CLASSPATH=D:\dir1\dir2\dir3\java\

That one should work. What does your javac or java command line look like?

MLRona at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...
# 4
I am compiling it through NetBeans IDE.
ahujava at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...
# 5

In the IDE when you write

package java.

a menu comes up that automatically shows the options like applet, io and so on.

When I do package dir1.

the menu that comes up says 'no suggestions'

whereas I am expecting it to show 'dir2' and so on.

Thanks for your help!

ahujava at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...
# 6
Then your expectations are wrong. There's nothing called "dir1" in your classpath. You have "com.dir4.dir5" in the classpath, so possibly "import com..." might produce a response.By the way, your package names need to be made more meaningful.
DrClapa at 2007-7-14 21:24:13 > top of Java-index,Java Essentials,Java Programming...