vscode-java-debug
vscode-java-debug copied to clipboard
The enclosing main class reports Main Class 'Main$Main1' doesn't exist in the workspace
If the main class is located in the enclosing class of a Java file,

launching debugger will throw error Failed to resolve classpath 'Main$Main1' doesn't exist in the workspace. Actually the class exists.

This issue only happens when the file Main.java is standalone Java file.
When the project name is not specified, the debugger will determine the project from the main class name. The approach is to use search engine to get the IJavaElement first, then resolve the associated project instance.
For the enclosing type Main1, we passed the fully qualified name Main$Main1 to jdt search engine, but it doesn't work because search engine doesn't support $ as enclosing separator. It only supports dot separated fully qualified name, e.g. Main.Main1 .
On the other side, in java launch parameters, main class value Main$Main1 works, but Main.Main1 doesn't work.
Search Engine and java.exe take different fully qualified class name format. Didn't find a perfect way to solve the problem.
If the main class name contains $ character, the search engine works well, this issue doesn't exist.
This issue just appears when the main method is located in an inner class. It's a corner case.
One possible solution is to add an extra search from main method if it's the enclosing type case.