vscode-java-debug
vscode-java-debug copied to clipboard
Support run/debug a JAR application
Currently, the debugger supports run/debug a Java application with main class. The request is to support run/debug a JAR application.
Is there any update on this? I have a multi-module maven project -- that also contains a fair number of dependencies -- that I'd really like to debug in VSCode. I can launch the "fat" jar (with dependencies inside) from the command line and it runs fine. But, I can't debug that. When I launch the main from VSCode, the debugger dies and tells me it can't load a class (that is clearly in a dependency jar). Seems like I need to be able to launch the "fat" jar from VSCode. Or is there another way?
Edit: Never mind. The code runs fine & I don't need to run the jar in debug. I had not configured my java runtime correctly in VSCode. I fixed it according to this link and now I'm running my maven project in debug as expected. https://code.visualstudio.com/docs/java/java-tutorial#_settings-for-the-jdk
Another approach is to customize your own launch command line in tasks.json, then use "preLaunchTask" setting in launch.json to invoke your task and attach a debugger to your application. See https://github.com/microsoft/vscode-java-debug/issues/120#issuecomment-417269773
+1 from 2023 march feedback
After somes tests, I found out VSCode likely reads the launch.json keys in such order:
java vmArgs classPaths|@argfile mainClass args
It seems we could leverage this limited behavior in order to debug a JAR file, just providing the JAR's path into vmArgs field, otherwise, the main class can't be loaded:
It is not the perfect behavior, since Java's launch.json requires a main class (otherwise it infers one), but it might be a workaround. I think to VSCode be able to run the JAR files properly, such requirement for a main class should be removed.