java in vscode

Asked 2 years ago, Updated 2 years ago, 101 views

I was going to be able to run java in vscode, but when I installed the Java Extension Pack and set the path of jdk, it says "Build failed" and I can't run it.I would appreciate it if you could help me.

java vscode

2022-09-30 15:31

1 Answers

We do not have enough information, so we would like to check various things, and we will list the possible errors and solutions.
"Also, if you write down the contents displayed on the debug console, it will be completed immediately, so if you write down the message that appears with ""Build failed"", we can solve it more simply."

○Confirmation
What happens if I compile on a console without using VSCode?
The steps are as follows (for Windows):

  • It is even better to specify the path of the jdk directly that you configured ("C:\Program Files\Java\jdk-11.0.2\bin\javac.exe" Hoge.java)

○Expected Error Cause No. 1 (Mistake Path)
Please allow me to check the settings as well.
Is it okay to set the PATH for JDK below?

"java.home": "C:\\Program Files\\Java\jdk-11.0.2"

Windows For Windows, you need to write two delimiters: \.
*You don't need to write up to bin
JR It should be JDK's PATH, not JRE's PATH.

○Expected error cause No.2 (filename and class name do not match)
Java must match the file name and class name.
If the filename is Hoge.java, the class name is Hoge.

You could do it below, so compare it to your situation.

"java.home": "C:\\Program Files\\Java\jdk-11.0.2"
public class Hoge{
    public static void main(String[]args) {
        System.out.println("test");
    }
}


2022-09-30 15:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.