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
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…
In the opened window “Debug configurations”, do a right-clic on Remote Java Application, and New:
Select the concerning sources projects:
Fill in the application server parameters corresponding to the values filled in the Catalina configuration:
Host : myserver.test.javablog.fr
Port : 8000
…and launch the debug session by clicking on Debug button:
…so, we could debug our application like deployed on a local server with breakpoints:
The console and standard output is done on the remote server, not in Eclipse view:
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
That’s all!!!
Huseyin OZVEREN