Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing files

Status
Not open for further replies.

mooster2

Programmer
Jan 26, 2004
21
CA
In C++, one can simply use something like
#include <iostream.h>
#include &quot;mycustomclass.cpp&quot;

where < > meant a C++ file that is in the C++ installation directory and libraries
and where &quot; &quot; meant a C++ is currently in the same directory than a C++ file that you are working on.

Now.. if I wanted to work with java, I'd know use this:
import java.io.*
but that's for core java files and libraries
how do add/import a java file that is in the same directory as the one i'm working:

Example:

I have 2 classes in my directory:

Hello.java
Meow.java
Meow.class
Meow has been compiled already
I want to be able to use an instance of class Meow inside of Hello.java -- how do I include Meow in it?

 
In 1.4 SDK you cannot &quot;import&quot; non-packaged classes. If they were in a package (typically in a jar file) you would do &quot;import com.acme.myclasses.*;&quot; as you would any other package.

For you case though, if your class files are in &quot;/usr/local/java&quot; you would simply add the directory to you CLASSPATH environment variable as such :

export CLASSPATH=$CLASSPATH:/usr/local/java

or for windows :

set CLASSPATH=%CLASSPATH%;C:\code\java

This will allow you to add non-packaged classes without the need for an import statement. This will also work for packaged classes that are not within a jar file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top