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 Apiqcloud:
1. Log into the Apiqcloud dashboard with your credentials and click the Config button for the application server in your environment:
< 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.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.< im 2 >
Don't forget to Save the changes with the appropriate button above the editor.
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.