vscode-java-debug icon indicating copy to clipboard operation
vscode-java-debug copied to clipboard

Support run/debug a JAR application

Open testforstephen opened this issue 6 years ago • 4 comments
trafficstars

Currently, the debugger supports run/debug a Java application with main class. The request is to support run/debug a JAR application.

testforstephen avatar Jun 20 '19 07:06 testforstephen

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

sbowman-mitre avatar Jun 03 '21 20:06 sbowman-mitre

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

testforstephen avatar Jun 07 '21 06:06 testforstephen

+1 from 2023 march feedback

testforstephen avatar Apr 27 '23 04:04 testforstephen

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:

image

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.

rogerdenisvieira avatar Jul 22 '23 03:07 rogerdenisvieira