How To Set The Classpath (Wiki forum at Coderanch) (original) (raw)

The CLASSPATH environment variable is used by Java to determine where to look for classes referenced by a program. If, for example, you have an import statement for my.package.Foo, the compiler and JVM need to know where to find the my/package/Foo class.

In the CLASSPATH, you do not need to specify the location of normal J2SE packages and classes such as java.util or java.io.IOException.

You also do not need an entry in the CLASSPATH for packages and classes that you place in the ext directory (normally found in a directory such as C:\j2sdk\jre\lib\ext). Java will automatically look in that directory. So, if you drop your JAR files into the ext directory or build your directory structure off the ext directory, you will not need to do anything with setting the CLASSPATH. But this directory was intended for official Java extensions from Sun. Its use by unofficial Java extensions isn't recommended.

Note that the CLASSPATH environment variable can specify the location of classes in directories and in JAR files (and even in ZIP files).


Be careful relying on the CLASSPATH too much. It can be convenient during development, but is often much less useful in a production situation.


Instructions on Setting the CLASSPATH on different Operating Systems

For Windows XP/2000/NT

For Windows ME/98/95

For Linux and other Unix variants


For more information on using the CLASSPATH correctly, take a look at Oracles tutorial on Managing Source and Class Files - http://download.oracle.com/javase/tutorial/java/package/managingfiles.html


CategoryHowTo