# Setting Up Environment Variables for a Java Application to Use Spotfire Enterprise Runtime for R

For a Java application to use the embedded TERR engine, you must prepare the environment.

## Procedure

1. Set the `JAVA_HOME` environment variable to the base of the Java installation.
   This step is necessary because the embedded TERR engine automatically loads the terrJava package, which requires this environment variable.
2. Set the `TERR_HOME` environment variable to the base of the TERR installation (that is, the directory containing subdirectories bin, library, and so on).
3. Set the Java classpath to include the file TERR_HOME/library/java/terrJava.jar, which contains the Java code for starting and controlling an embedded TERR engine.
   The Java classpath can be set by setting the `CLASSPATH` environment variable, or giving the `- classpath` argument when starting Java.
4. Set the appropriate environment variable so Java can access the TERR engine libraries.
   - On Windows, you must add TERR_HOME/bin/x64 to the PATH environment variable.
   - On Linux, you should add TERR_HOME/lib/x86_64-unknown-linux/ to the `LD_LIBRARY_PATH` environment variable.

## What to do next

To test that these environment files are set correctly, the class `com.tibco.terr.TerrJava` (in terrJava.jar) contains a `main` method that implements a simple TERR console. See Example for setting Windows environment variables or Example for setting Linux environment variables.