Java

This guide walks you through setting up Application Performance Monitoring (APM) on a Go application. You can also check the Installation page in your Middleware Account for these instructions. To test the Java APM feature, use this example code.

Prerequisites

Before you begin, ensure you have the following:

PrerequisiteDescription/How to
Java Development Kit (JDK)Version 8 or higher installed on your server.
The Middleware Infra agentTo install the Infra Agent, see our Installation Guide.
Access to your Java application's deployment environmentThis could be a Tomcat, Jetty, JBoss, WildFly, Spring Boot, or any other JVM-based application server.
Middleware.io AccountAn active account with Middleware.io to access your organization's API key.
Internet ConnectivityThe server running your Java application must have outbound internet connectivity to communicate with the Middleware.io platform.

Installation steps

Step 1: Download the Middleware.io Java Agent

Download the latest Middleware instrumentation JAR file from the Github Release Page.

Step 2: Place the Agent JAR file

Place the downloaded middleware-javaagent.jar file in a location accessible by your Java application. A common practice is to create a dedicated directory for agents, e.g., /opt/middleware-agent/.

Step 3: Configure the Java application to load the agent

To enable the Middleware.io agent, you need to add a JVM argument to your Java application's startup script. This argument tells the JVM to load the agent before your application starts.

Common Scenarios:

Application Server/TypeConfiguration MethodExample
Standalone Java Application (e.g., Spring Boot JAR)Add -javaagent to java -jar command.java -javaagent:/opt/middleware-agent/middleware-javaagent.jar -jar your-application.jar
TomcatEdit setenv.sh (Linux/macOS) or setenv.bat (Windows) in TOMCAT_HOME/bin.Linux/macOS: export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/middleware-agent/middleware-javaagent.jar" <br> Windows: set "CATALINA_OPTS=%CATALINA_OPTS% -javaagent:/opt/middleware-agent/middleware-javaagent.jar"
JettyModify start.ini or similar configuration file.--module=agent <br> -javaagent:/opt/middleware-agent/middleware-javaagent.jar
JBoss/WildFlyEdit standalone.conf (standalone) or domain.conf (domain) in JBOSS_HOME/bin.Linux/macOS: JAVA_OPTS="$JAVA_OPTS -javaagent:/opt/middleware-agent/middleware-javaagent.jar" <br> Windows: set "JAVA_OPTS=%JAVA_OPTS% -javaagent:/opt/middleware-agent/middleware-javaagent.jar"
Other Application ServersConsult specific application server documentation for adding JVM arguments.Add -javaagent:/path/to/middleware-javaagent.jar to the JVM arguments.

Restart your application server to update your configurations.

Step 4: Restart your application

After making the necessary changes to your application's startup configuration, you must restart your Java application for the Middleware.io agent to be loaded and begin monitoring.

Step 5: Verify Installation

After restarting your application, follow these steps to confirm the Middleware.io agent is running and reporting data:

  1. Check Application Logs:

    • Examine your application's standard output or log files (e.g., catalina.out for Tomcat, or your application's specific log file).
    • Look for messages indicating that the Middleware.io agent has started successfully. These messages often begin with [Middleware Agent] or similar.
    • You should see messages like:
    • If you see errors, refer to the Troubleshooting Guide.
  2. Generate Some Application Traffic:

    • Interact with your Java application to generate some traffic (e.g., make a few HTTP requests, trigger some database calls). This ensures there's data for the agent to collect and send.
  3. Check your Middleware.io dashboard:

    • Log in to your Middleware.io dashboard.
    • Navigate to the APM section or your list of monitored applications.
    • Within a few minutes, you should see your application listed (using the name configured by mw.agent.application_name) and metrics (like CPU, memory, request rates) should start appearing.

If you don't see your application or data after these steps, check the troubleshooting page for details on how to fix this.

To further configure the installed Java APM (e.g., install the APM on Docker and Kubernetes, customize the APM's behaviour using environment variables, enable debugging mode, use head sampling, or enable continous profiling), follow the steps in the configuration page.

Need assistance or want to learn more about Middleware? Contact our support team at [email protected].