# Manually setting the CLASSPATH environment variable

You can set the CLASSPATH environment variable in the operating system either temporarily, permanently, or at run time when you start your Java application and the JVM.

The classpath is a list of the class libraries that are needed by the JVM and other Java applications to run your program. There are scripts that are included with Derby that can set up the classpath to run the Derby tools.

If you want to call the Derby tools directly using Java and not using the scripts, you must manually set the CLASSPATH environment variable.

In most development environments, it is best to temporarily set the CLASSPATH environment variable in the command line shell where you are entering commands.

Derby provides several scripts in the DERBY_HOME/bin directory to help you set your classpath quickly. These scripts are:

setEmbeddedCP
  Use the setEmbeddedCP script to set the classpath when the database engine is used in embedded mode. This script adds the derby.jar, derbytools.jar and derbyoptionaltools.jar files to the classpath.
setNetworkServerCP
  Use the setNetworkServerCP script to set the classpath when you want to start the network server. This script adds the derbynet.jar file to the classpath.
setNetworkClientCP
  Use the setNetworkClientCP script to set the classpath when you want to access databases using the network client. This script adds the derbyclient.jar, derbytools.jar and derbyoptionaltools.jar files to the classpath.

To set the classpath temporarily, run the script that is appropriate for your environment every time that you open a new command window.

Note that these scripts behave slightly differently on UNIX systems and on Windows systems. On Windows systems, running the script in your command shell will set the environment variables for your shell.

On UNIX systems, you need to use the "dot" or "source" command to ensure that the script is run in the calling shell's environment. Otherwise, when a script is run, it launches a new shell for that script. The CLASSPATH is set within that shell. Once the script is complete, that shell exits and you are returned to your shell. The CLASSPATH is changed only for the shell that the script was running in. The CLASSPATH in your shell is unchanged.

The UNIX shell scripts are known to run successfully in the Bash shell, and you may need to modify them slightly if you are using a different UNIX shell.

Here are examples of running the scripts, then displaying the classpath that the script sets:

- On UNIX, using the "dot" command to invoke the script, a sample session might be as follows:

      sh-2.05b$ echo $CLASSPATH
      sh-2.05b$ DERBY_HOME=/derby/db-derby-10.X.Y.0-bin
      sh-2.05b$ . $DERBY_HOME/bin/setEmbeddedCP
      sh-2.05b$ echo $CLASSPATH
      /derby/db-derby-10.X.Y.0-bin/lib/derby.jar:/derby/db-derby-10.X.Y.0-bin/lib/derbytools.jar:/derby/db-derby-10.X.Y.0-bin/lib/derbyoptionaltools.jar:
      sh-2.05b$ java org.apache.derby.tools.ij
      ij version 10.X
      ij> quit;

- On UNIX, using the "source" command to invoke the script, a sample session might be as follows:

      -bash-2.05b$ echo $CLASSPATH
      -bash-2.05b$ export DERBY_HOME=/derby/db-derby-10.X.Y.0-bin
      -bash-2.05b$ source $DERBY_HOME/bin/setEmbeddedCP

- On Windows, a sample session might be as follows:

      C:\derby\db-derby-10.X.Y.0-bin\bin>echo %CLASSPATH%
      %CLASSPATH%
      C:\derby\db-derby-10.X.Y.0-bin\bin>set DERBY_HOME=C:\derby\db-derby-10.X.Y.0-bin
      C:\derby\db-derby-10.X.Y.0-bin\bin>setEmbeddedCP.bat
      C:\derby\db-derby-10.X.Y.0-bin\bin>echo %CLASSPATH%
      C:\derby\DB-DERBY-10.X.Y.0-bin\lib\derby.jar;C:\derby\DB-DERBY-10.X.Y.0-bin\lib\derbytools.jar;C:\derby\DB-DERBY-10.X.Y.0-bin\lib\derbyoptionaltools.jar;
      C:\derby\db-derby-10.X.Y.0-bin\bin>java org.apache.derby.tools.ij
      ij version 10.X
      ij> quit;

For more information on running the `ij` and `sysinfo` utilities, see the Derby Tools and Utilities Guide
Parent topic: Setting up your environment