In this article, we will discuss a practical example of remote debugging using the Eclipse IDE and the JBOSS Wildfly application server in a Windows environment.
There are situations in which it is difficult to reproduce a problem highlighted in a test or production environment and, for a quick resolution, we would like to connect our development environment to a remote server, introduce breakpoints within the code and run tests by analyzing the execution flow. The following is a practical example of remote debugging via the Eclipse IDE and the JBOSS Wildfly application server in the Windows environment.
Consider as an example debugging a web application on a remote server. In order to connect the development IDE, the server itself must be run by specifying a series of input arguments for the Java Virtual Machine. Specifically, the startup instruction of the application server must contain the following parameters: <code>-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n</code>.
<code>-Xdebug</code> enables remote JVM for debugging mode, while <code>-Xrunjdwp</code> specifying connection details including:
transport : can assume the values <code>dt_socket</code> for a socket interface or <code>shmem</code> for the use of a shared memory zone useful when the application and the debugger reside on the same machine.
address : listening port of the application server for remote debugging.
suspend : can assume the values <code>y</code> to indicate the suspension of the application until there are no remote remote debuggers connected or <code>n</code> to indicate the non-suspension of the application even in the absence of remote connected debuggers.
In our case we are going to realize a simple Dynamic Web Application , containing a servlet to be recalled, using the Eclipse wizard. We export the <code>war</code> application package , insert it in <code>deployments</code> the server directory and prepare for the launch of JBoss Wildfly with the parameters previously illustrated.
To edit the arguments provided in input to the JVM in the startup phase of JBoss, we edit the file <code>standalone.conf.bat</code> contained in <code>bin</code> the server directory by changing the line <code>set “JAVA_OPTS=-Xms64M -Xmx512M -XX:MaxPermSize=256M”</code> in <code>set “JAVA_OPTS=-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -Xms64M -Xmx512M -XX:MaxPermSize=256M”</code>.
<code>bin</code> Let’s position ourselves in the JBOSS directory using a Windows console, and run the file <code>standalone.bat</code>. We will see in the initial phase a print similar to the following:
where we can see the presence of the parameters necessary to start in remote debug mode. We open the Eclipse IDE in which it is present at our web application and insert a breakpoint inside the test servlet code. Then we use the Debug icon, present on the IDE toolbar, choosing the “Debug Configurations” option when opening the menu:
In the next screen select “Remote Java Application” and click on the toolbar button to create a new launch configuration as shown in the following image:
The result of the previous operation is the opening of the panel to configure the connection details of our application. In the example, the name of the application to be debugged remotely <code>RemoteTestWebApp</code>, name that we are going to insert in the “Project” field. Instead, we must take care to provide the correct IP address and port number of the remote server:
We just have to click on the debug button and open the browser to retrieve the web address of the servlet in the demo project. We should have the debug entry of the IDE at the first breakpoint entered by us.