VSCode Java Debugger for Java Build failed Causes and countermeasures

A story about debugging Java with Visual Studio Code

キャプチャ.PNG image.png

Debugger for Java Build failed

sample code

I referred to here for settings etc. Getting Started with Java Programs Using Visual Studio Code

test.java


public class test {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++)
            sayHello();
    }

    private static void sayHello() {
        System.out.println("Hello World!");
    }
}

It works at first When I reopen VS Code from the second time onward and execute it again, I encounter an event that I can not debug due to an error

VSCode Java Debugger for Java Build failed error

キャプチャ.PNG

this.

In the debug console

error:Main class test not found or could not be loaded

Come out.

image.png

"The java main class was not found or could not be loaded" 「VS code Debugger for Java Build failed」 When you google Many articles say that the path is wrong. But with such a simple source, it doesn't make sense to work the first time.

Cause

The problem is the VS Code workspace. From [File]-> [Open Folder] in VS Code If you specify the folder where test.java is located, the workspace will be one level higher for some reason. : sweat_smile :: sweat_smile :: sweat_smile ::

VScode refers to launch.json when debugging, but this is what is created automatically

{
	//You can use IntelliSense to learn the available attributes.
	//Hover and display the description of existing attributes.
	//Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
	"version": "0.2.0",
	"configurations": [
		{
			"type": "java",
			"name": "Debug (Launch)",
			"request": "launch",
			"cwd": "${workspaceFolder}",
			"console": "internalConsole",
			"stopOnEntry": false,
			"mainClass": "",
			"args": ""
		},
		{
			"type": "java",
			"name": "Debug (Launch)-test",
			"request": "launch",
			"cwd": "${workspaceFolder}",
			"console": "internalConsole",
			"stopOnEntry": false,
			"mainClass": "test",
			"args": ""
		},
		{
			"type": "java",
			"name": "Debug (Attach)",
			"request": "attach",
			"hostName": "localhost",
			"port": "<debug port of remote debuggee>"
		}
	]
}

"cwd": "${workspaceFolder}" I have this guy so I go to the workspace to look for test.java If you perform the operation of [File]-> [Open Folder], there is no such thing because the workspace is one level higher. : head_bandage: Therefore Error: Main class test was not found or could not be loaded Will be.

Countermeasures

As a countermeasure, the location of the workspace should be the location where test.java is located. File-> Save Workspace As Save as a suitable name from here .code-workspace I can do it from the next time File-> Open Workspace OK if you open this file from

Why do you do [File]-> [Open Folder] I didn't know if the workspace would go up one level. There may be some settings: thinking:

Recommended Posts

VSCode Java Debugger for Java Build failed Causes and countermeasures
Build a development environment for Docker, java, vscode
Countermeasures for Java OutOfMemoryError
Java while and for statements
AWS SDK for Java 1.11.x and 2.x
Java for beginners, expressions and operators 1
Java for beginners, expressions and operators 2
Build Java development environment (for Mac)
Classes and instances Java for beginners
Countermeasures for FDclone build failure on CentOS 8
[Java] for Each and sorted in Lambda
[For beginners] Difference between Java and Kotlin
[Java] Proxy for logging SQL and SQL results
Java management and STS (Eclipse) build path settings
I studied for 3 weeks and passed Java Bronze
Build and test Java + Gradle applications with Wercker
Build Java environment and output hello world [Beginner]
Build Java x Spring x VSCode x Gradle on Docker (1)
Kantai Collection Java # 1 Classes and Objects [For Beginners]
SourceMapPathOverrides setting memo in VSCode Debugger for Chrome
Technical causes and countermeasures for points addicted to Android apps & Kotlin (3. Processing related to Android images)