Hi,

In this article, I will describe the “remote debug” on a server and its use in the IDE like Eclipse. This action could be useful in debugging case linked to the environment problematic cases.

Tomcat Server Configuration
First, it is necessary to configure the application server.

Stop the application server (in our case Tomcat):

  • In Unix: /etc/init.d/tomcat stop
  • In Windows: D:\Apache Software Foundation\Tomcat 7.0\bin\shutdown.bat or in the Server/Services manager

Modify the Catalina configuration in order to add the debug options
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n:

  • In Unix: to the CATALINA_OPTS variable in Catalina.sh
  • In Windows: in the Java Options in the Tomcat properties
    img123

Modification of compilation options
Then, in order to debug an appplication, it’s necessary to compile its sources with the debugging options:
debug=”on” debuglevel=”lines,vars,source”

For example, in an ANT build xml file, it’s necessary to modify the line concerning the compilation javac like:

<javac srcdir="src/main/java" encoding="UTF-8" destdir="${CLASSES_PATH}" debug="on" debuglevel="lines,vars,source" verbose="false">
<classpath refid="compilationClasspath"/>
</javac>

Generate the WAR, deploy it on the application server and restart the server:

  • In Unix: /opt/tomcat/bin/startup.sh
  • In Windows: D:\Apache Software Foundation\Tomcat 7.0\bin\start.bat or in the Server/Services manager

Eclipse Configuration
Finally, in IDE (Eclipse in our example), go in the menu : Run / Debug Configurations…
remote-debug-124

In the opened window “Debug configurations”, do a right-clic on Remote Java Application, and New:
remote-debug-125

Select the concerning sources projects:
remote-debug-126

Fill in the application server parameters corresponding to the values filled in the Catalina configuration:
Host : myserver.test.javablog.fr
Port : 8000

remote-debug-127
…and launch the debug session by clicking on Debug button:remote-debug-129

…so, we could debug our application like deployed on a local server with breakpoints:
remote-debug-129 2
remote-debug-130

The console and standard output is done on the remote server, not in Eclipse view:
remote-debug-130 2
remote-debug-131

remote-debug-132

The standard output will be visible in:

  • In Unix: tail -f /opt/tomcat/logs/Catalina.out
  • In Windows: D:\Apache Software Foundation\Tomcat 7.0\logs\tomcat7-stdout-2014-02-10.log

remote-debug-1322

That’s all!!!

Huseyin OZVEREN