What Is an Export PATH & CLASSPATH?
In the Microsoft Windows, Linux and Solaris operating systems, PATH and CLASSPATH are what are known as environment variables. Environment variables are named objects that contain information, such as drive, path or file names, used by one or more applications. If you’re running certain versions of the command interpreter, or shell under Linux or Solaris, you’ll need to export the PATH and CLASSPATH environment variables before they have an effect.
-
PATH
-
The PATH environment variable is often used to specify the full path to the executable programs required by the Java Development Kit, a development environment for building Java applications, created by Sun Microsystems, so that developers don’t need to type the path every time they execute a program.
Setting and Checking PATH
-
In Bourne shell, Bourne again Shell and Korn shell, you can set the PATH environment variable permanently in your startup file. In Bourne shell, edit your startup file, called “.profile”, and include the line “PATH=/usr/local/jdk1.7.0/bin:” followed by the line “export PATH”. Check the PATH environment variable is set correctly by running the command “./.profile” to execute your startup file and then running the command “java –version”. If PATH is set correctly, this command will print the version of the JDK. If not, the command will return a “Command not found” error.
-
CLASSPATH
-
In the same way that the PATH environment variable tells the shell where to look for executable programs, so the CLASSPATH environment variable tells the Java Development Kit where to look for user classes, which are effectively “blueprints” from which individual Java objects are created. You can set the CLASSPATH environment variable in the same way as the PATH environment variable. When it comes to checking if CLASSPATH is set correctly, type the command “echo $CLASSPATH”. If CLASSPATH is set correctly, Linux or Solaris will report the path. If not, you’ll see a “CLASSPATH: Undefined variable error.”
Java Classes
-
CLASSPATH tells the Java Development Kit where to find classes that are not part of the Java platform, or extensions to it. By default, CLASSPATH is set to the current working directory, but CLASSPATH needs to include any classes compiled with the primary Java compiler, known as “javac”. To make life easier for developers, it is possible to use the wildcard character (*) in the CLASSPATH environment variable to specify all the JAR files in a particular directory, without naming each individual file.
-