Java Imports

Clear

Gawd
Joined
Mar 15, 2002
Messages
876
I tried googling without success, because I don't really know how to word this question very well. Anyhow, how do you make outside classes importable. For instance, I need to use the SMNP4J API packages (which are available for free), but I'm not sure how I can set it up so that I can do this with any java file stored anywhere on a windows machine:

Code:
import org.snmp4j.*;

Anyone got some suggestions? If I'm not clear about what the problem is just let me know. Thanks for all the help.

- Dave
 
I'm not completely sure what the question is but you should be able to import it if it is in your class path.
 
There are 2 steps to getting classes imported. First the .jar file or the directory of the root of the class tree needs to be in the classpath.

For example if your .class files are int c:\classes\org\snmp4j\ you would put
c:\classes in your classpath. If it's a jar file c:\jars\snmp4j.jar you would put c:\jars\snmp4j.jar in your classpath.

the classpath can be set in a couple ways. You can use an environment variable CLASSPATH. Or you can use the -cp argument to the java vm.

Next you need to import the classes into your current class namespace. This is done with the import keyword. It looks like you have that part figured out though.
 
Back
Top