0

i have problem when i am accessing package of different directory.

can we access a package in a single java file that are lies in two different drive/directories?

Eg. My one package p1 is in d:/ having class abc.java
My another package p2 is in e:/ having class pqr.java

can i access both this classes in single java file reside at desktop?

how to do so?
please explain.

Thanks

2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by sepp2k
1

Yes, you can use class files from different directories by adding all the directories to your classpath. If you're using an IDE, you can do so in your project's settings. If you're compiling from the command line, you can use the -classpath switch or the CLASSPATH environment variable to set the class path. On Windows multiple directories are separated by a semicolon.

So if you have p1.abc in d:\stuff\p1\abc.class and p2.pqr in e:\otherstuff\p2\pqr.class, you can compile a class that uses both those classes from the command line like this:

javac -classpath d:\stuff;e:\otherstuff MyClass.java
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.