Skip to main content

Configure the Java agent for Tomcat

First, download the Java agent JAR from one of these repositories:

Use the guidelines below to configure the Java agent depending on how you run Contrast with Tomcat.

Run from Windows or Unix

The CATALINA_OPTS environment variable is used to pass configuration flags and system properties to the JVM that runs the Tomcat server.

Tomcat recommends using a setenv script to specify environment variables. You can learn more about the setenv script, including how to find or create it as needed, by consulting RUNNING.txt, which is included with every distribution of Tomcat.

To enable Contrast add the -javaagent configuration to CATALINA_OPTS in either, if running on a Unix-like operating system, or setenv.bat if running on Windows. For example:

  • Windows:

    set "CATALINA_OPTS=%CATALINA_OPTS% -javaagent:<YourContrastJarPath>"
  • Unix:

    export CATALINA_OPTS="$CATALINA_OPTS -javaagent:<YourContrastJarPath>"

Run on the Tomcat service in Windows

  1. If you run Tomcat as a service, open the Tomcat service manager and change the JVM options to add the agent.

  2. Double-click the Tomcat icon in the system tray (or right-click and select Configure). (If the icon isn't there, you might have to start it manually by running tomcat9w.exe in the Tomcat bin directory.)

  3. Switch to the Java tab to see where you need to add the -javaagent flag.

Run Tomcat with Java 2 security

  1. Create a contrast.policy file that contains this code (or append it to the catalina.policy file). Replace <YourContrastJarPath> with the path to your Contrast JAR file. For example:

    grant codeBase "file:<YourContrastJarPath>" {
  2. Append the contrast.policy file to the $CATALINA_HOME/conf/catalina.policy file. No additional configuration is needed. Run your Tomcat installation with command-line parameter -security.