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 setenv.bat
If you have a setenv.bat or setenv.sh file as recommended by Tomcat, add the -javaagent
configuration in that file in CATALINA_OPTS
.
Run from Windows on Unix
Create a new startup script. Replace
<YourContrastJarPath>
with the path to your Contrast JAR file and substitute your Tomcat server for your environment.Windows: Use
startup-with-contrast.bat
, for example:set "CATALINA_OPTS=%CATALINA_OPTS% -javaagent:<YourContrastJarPath>" call <TomcatDirectory>\bin\startup.bat
Unix: Use
startup-with-contrast.sh
, for example:export CATALINA_OPTS="$CATALINA_OPTS -javaagent:<YourContrastJarPath>" <TomcatDirectory>/bin/startup.sh
This should enable the Contrast JVM parameters and call the startup script. This new script will start up your server with Contrast.
Run on the Tomcat service in Windows
If you run Tomcat as a service, open the Tomcat service manager and change the JVM options to add the agent.
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.)
Switch to the Java tab to see where you need to add the
-javaagent
flag.
Run Tomcat with Java 2 security
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>" { permission java.security.AllPermission; };
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
.