How to perform Java Agent Integration

Java Agent Integration

A Java Agent is an interceptor in front of the application’s main method, executed in the same JVM (Java Virtual Machine), loaded by the same system class loader and governed by the same security policy and context. Generally, it represents a .jar package with the PreMain-Class method, which implements the mechanism of re-defining the running classes’ content on the bytecode level with the help of java.lang.instrument. And in order to designate such an applet to be launched at startup (just after the JVM is initialized), the special -javaagent parameter is used.

So, let’s discover how I can easily add a Java Agent to my node and, as a result, get an ability to deploy and operate with agent-based applications at CloudJiffy:

1. Log into the CloudJiffy dashboard with your credentials and click the Config button for the application server in your environment:


Tip: In case if you don’t have an environment yet, you can easily create a new one by clicking the New environment button in the top left corner of the dashboard and choosing the desired application server (for example, Tomcat) at the Java wizard tab.

 
2. In the opened configuration file manager, you can upload your Java agent .jar file to any preferable location. Use the Actions list at the top panel (for the current folder) or the context menu when hovering over the particular directory.


3. Now, switch to the server/variables.conf file, which is intended for setting your custom variables (including the JVM options), and specify the javaagent parameter with a path to the required jar file. For example, according to the environment variables guide, the path to the file in the Tomcat home directory we’ve uploaded above will be:

javaagent:/opt/tomcat/temp/my-java-agent.jar


Note that the variables.conf file already contains one Java Agent declared, namely:

javaagent:/var/lib/jelastic/java/jelastic-gc-agent.jar

Don't forget to Save the changes with the appropriate button above the editor.

Note: When setting up Java Agent for Jetty and TomEE, follow the same approach of editing the variables.conf file for specifying the auxiliary JVM arguments (as described above). Glassfish is different and uses a domain.xmlconfiguration file instead - see this article for the details.

3. To apply the newly added settings, I need to restart my container using the same-named option:




That’s all! Now, your custom Java agent is up and running.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 9707