How Can We Help?
< All Topics
Print

Java Agent

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 the 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 the ability to deploy and operate with agent-based applications at BitssCloud:

1. Log into the BitssCloud 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.

< im 1 >

2. 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.jarIt 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.

< im 2 >

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, you need to Restart your container using the same-named option:

< im 3 >

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.

Table of Contents