Reputation: 671
I'm trying to remotely debug a Java web application running on Tomcat 7 using VS Code. The debugger successfully attaches to the remote instance and catches breakpoints in the call stack, but the source code/debugging symbols do not load.
My Setup:
Java version : java 8.0.352-zulu
Remote machine: Running Tomcat 7 with JPDA enabled (port 8000)
Local machine: macOS with VS Code and an SSH tunnel for debugging
Build tool: maven 3.8.1
IDE : VS Code v1.96.4
Debugging configuration: VS Code with Debugger for Java extension v0.58.1
Steps Taken So Far:
1- Ensured debug symbols are included in the compiled classes:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
</configuration>
</plugin>
</plugins>
</build>
2- Enabled remote debugging on Tomcat (on the remote machine):
$ export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
$ su - user001 -c "$CATALINA_HOME/bin/catalina.sh jpda run"
3- Opened an SSH tunnel to forward the remote debug port:
% ssh -L 8000:localhost:8000 user001@remote-server-ip
4- Configured VS Code (.vscode/launch.json):
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"request": "attach",
"name": "Attach to Local Tunnel",
"hostName": "localhost",
"port": 8000,
"sourcePaths": [
"/absolute/path/to/my/source/code/src/main/java"
]
}
]
}
5- Verified the compiled .class
files contain debug symbols (on the remote server):
$ javap -v $CATALINA_HOME/webapps/myapp/WEB-INF/classes/com/myapp/reporting/ReportServiceImpl.class | grep "LineNumberTable"
✅ Output confirms LineNumberTable exists.
6- Selected "Attach to Local Tunnel" in VS Code's "Run and Debug panel" and then Started Debugging (▶️).
Issue:
The debugger connects successfully and breakpoints trigger, but the corresponding source file is not loaded in VS Code.
Things I Tried But Didn't Work:
Restarted VS Code and deleted .vscode
settings and added a new clean .vscode/launch.json
file.
Rebuilt the web application and re-deployed it to Tomcat (with debug symbols included).
Used $ netstat -tulnp | grep 8000
to confirm the remote port is open.
Used % nc -vz localhost 8000
to verify the SSH tunnel is working on my end.
Question:
Why is VS Code unable to load the correct source file even when breakpoints are hit?
How can I force VS Code to map the source files correctly when remote debugging my Java web application?
Any help or suggestions would be greatly appreciated!
Upvotes: 2
Views: 71