Remote Debugging

Remote Debugging

With a public IP attached to the application server, a Java application running on the platform can be connected to a debugger in an IDE for remote code inspection and breakpoint testing.

How Remote Debugging Works

  • The application opens a socket and listens for debugging instructions.
  • The debugger in the IDE connects to the same socket and sends debug commands.
  • The debug port configured on the server must match the port used by the IDE.

Create the Environment

1Create a new environment

Sign in to the dashboard and click Create environment.

Create environment button
Start environment creation from the dashboard.

2Select the application server

Choose the required instance, such as Tomcat, configure the Cloudlet limit, enable a public IP, enter the environment name, and click Create.

Environment wizard with public IP enabled
Create the Java environment and enable a public IP.

3Copy the public IP

Expand the environment and open the additional node information to view the assigned public IP address.

Public IP address of the application server
Use the public IP as the debugger host address.

Deploy the Application

1Upload the Java archive

Upload the Java package through Deployment Manager.

Upload Java archive
Upload the application archive to Deployment Manager.

2Deploy the application

Select the newly created environment and deploy the uploaded package.

Deploy Java application
Deploy the application to the debugging environment.

The example application initialises three variables one after another:

package com;

public class RemoteDebugger {

    public void start () {
        int a, b, c;

        a = 1;
        System.out.println("a = " + a);

        b = 2;
        System.out.println("b = " + b);

        c = 3;
        System.out.println("c = " + c);
    }
}

Configure Remote Debugging

1Attach a debugger in the IDE

Open the project in an IDE such as NetBeans and select Debug Main Project > Attach Debugger.

Attach debugger in NetBeans
Create a new remote debugger connection.

2Configure the socket connection

Select the connector type, enter the public IP as the host, specify the debug port, and optionally define a timeout.

NetBeans socket debugger settings
Configure the host, port, connector, and timeout.

3Open Tomcat configuration

Return to the dashboard and click Config for the Tomcat node.

Tomcat Config button
Open the Tomcat configuration file manager.

4Add debug JVM arguments

Open variables.conf and add:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000
Tomcat variables.conf debug arguments
Add the remote-debugging JVM arguments to variables.conf.
Port matching: The port in variables.conf must be identical to the port configured in the IDE debugger.

Save the configuration and restart Tomcat.

Test with Breakpoints

1Add a breakpoint

Place a breakpoint before the final variable assignment and start the attached debugger.

Breakpoint in NetBeans
The application pauses before initialising the third variable.

Check the Tomcat logs. Only the first two values should be printed while execution is paused:

Tomcat logs before final variable assignment
The log shows values for variables a and b only.

2Move the breakpoint

Move the breakpoint one line lower and continue debugging.

Breakpoint moved to the next line
The debugger now allows the third variable to be initialised.
Tomcat logs after breakpoint moved
The log now shows all three variable values.
The same Tomcat procedure is also suitable for Jetty.

GlassFish Configuration

For GlassFish, add the debug arguments through the GlassFish Administration Console.

  1. Use the credentials sent when the environment was created to sign in to the GlassFish Admin Console.
  2. Open gfcluster-config > JVM Settings.
  3. On the General tab, configure the debug mode and debug options.
  4. Open JVM Options and add -Xdebug.
  5. Add -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000.
  6. Save all changes and restart GlassFish.
GlassFish Admin Console login
Sign in to the GlassFish Administration Console.
GlassFish debug options
Configure the GlassFish debug mode and JDWP parameters.
GlassFish JVM options
Add the required JVM debugging arguments.

What’s next?