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:
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:
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.
Don't forget to Save the changes with the appropriate button above the editor.
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.