Last update on .

There are two steps to using a library from a jar file in your program. First, you need to import the libraries from the jar file that you would like to use into your source code. Second, make sure that your CLASSPATH environmental variable is set. Only the second step warrants additional discussion.

When you compile your program your CLASSPATH environmental variable must be set to point to the jar file that you will want to use; not to the directory, but to the actual file. You can set your CLASSPATH variable in two ways: use the export command to put it into your environment, or use the -classpath flag on the javac compiler and java interpreter. If there is no CLASSPATH variable set, then java assumes that your classpath is the current directory (“.”). If it is set then it will be used instead of the current directory. This means that if you don’t include the “.” in your classpath, when you run your program with the java command it will be unable to find the classes located in your current directory. You can separate multiple entries in your classpath with the colon (“;”).

Note: you do not need to unjar a jar library to use it.


Pingbacks are closed.


Comments are closed.