Installing the Snyk runtime agent for Java
Install the Snyk runtime agent for Java:
- Download the runtime agent from this link and unzip the archive.
- From the extracted files, copy snyk-java-runtime-agent.jar alongside your application files.
- Create a snyk-agent.properties file at the same location as the agent jar file. The properties file should contain the Snyk project ID. For example:
- Add the agent as a command-line argument to the Java command that you use to start your application. For example:
java -javaagent:path/to/snyk-java-runtime-agent.jar -jar my-app.jar
- If you are using Apache Maven, add the following jar file to your Maven options environment variable as follows:
- If you are using JavaEE containers such as GlassFish, add the following jar file to the JVM Options:
- 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:
snyk-agent initialisation: startup snyk-agent initialisation: trying: /opt/app-1/agent/snyk-agent.properties snyk-agent initialisation: switching logging to: /opt/app-1/agent/snyk-logs/agent-log-2001-02-03T04:05:06.log
Example of Java code when Snyk runtime agent is added successfully