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 classloader 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 you can easily add a Java Agent to your node and, as a result, get an ability to deploy and operate with agent-based applications at Jelastic:

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

Tip: In case you don’t have an environment yet, you can easily create a new one by clicking the New environment button at 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 manager, hover over the home folder in the list to the right and click on the appeared Upload button:

Choose the local .jar file with your agent and confirm its uploading, so it will be stored within the above mentioned 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

It is designed to improve the automatic memory management (through periodical calling the garbage collection operations when it’s required) and is run at all Java application servers by default. Please, do not remove this setting until you’d like to disable the GC agent.

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.xml configuration file instead - see this article for the details.

4. To apply the newly added settings, you need to Restart your container using the same-named option:

That’s all! And in case you are interested in other configurations, that can be accomplished within your Java server, please refer to this guide.