Snyk Documentation

Snyk agent for Java

Work with Runtime monitoring for Java as follows:

Installing the Snyk agent

Add the Snyk agent to your project in order to start using Snyk Runtime Monitoring for your Java applications.

  1. Download the runtime agent and unzip the archive.
  2. From the extracted files, copy:snyk-java-runtime-agent.jaralongside your application files.
  3. Create a file at the same location as the agent jar file.
    The properties file should contain the Snyk project ID.
    For example:
  4. Add the agent as a command-line argument to the Java command that you use to start your application.
    For example:
    -javaagent:path/to/snyk-java-runtime-agent.jar -jar my-app.jar
  5. Add the jar file as follows:
    • If you are using Apache Maven, add the following file to your Maven options environment variable:
    • If you are using JavaEE containers such as GlassFish, add the following file to the JVM Options:
  6. Once you have successfully added the agent, logging begins to appear in the stderr (standard error) file shortly after the JVM (Java virtual machine) starts up, as in the following example:
    //Example of successful Java agent installation
    snyk-agent initialisation: startup
    snyk-agent initialisation: trying: /opt/app-1/agent/
    snyk-agent initialisation: switching logging to: /opt/app-1/agent/snyk-logs/agent-log-2001-02-03T04:05:06.log

Upgrading the Snyk agent

  1. Download the runtime agent and unzip the archive.
  2. From the extracted files, copy snyk-java-runtime-agent.jar and replace the existing one.

Uninstalling the Snyk agent

To remove the agent:

  1. Remove these .jar and .properties files, which you added to your project during installation:
  2. Remove the agent command-line argument from the Java command: