Home  >  Article  >  Development Tools  >  What to do if vscode debugging cannot load the class

What to do if vscode debugging cannot load the class

藏色散人
藏色散人Original
2020-03-31 09:37:543795browse

What to do if vscode debugging cannot load the class

What should I do if vscode debugging cannot load a class?

visual studio code debugging java error: The main class cannot be found or cannot be loaded

javavisual-studio-code

As the title:

Use Two java plug-ins on the official website are used to build a java development and debugging environment. The debugging configuration file is as follows:

Recommended learning: vscode tutorial

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)",
            "request": "launch",
            "mainClass": "JavaTester",
            "args": ""
        },
        {
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 0
        }
    ]
}

When debugging, errors have been reported: The main class JavaTester cannot be found or cannot be loaded. .

java.home is confirmed to be configured correctly, the PC's environment variables are also configured, the classpath is also configured as required, and the local terminal debugging is also passed. I can't find the main class here. Is there something wrong with the configuration of mainClass? Is there any requirement for this configuration?

I just want to do some simple demo-type java development, that is, only run a single java file.

Solution:

add configuration classPaths to launch.json

{
    "type": "java",
    "name": "Debug (Launch)",
    "request": "launch",
    "classPaths": [
        "(你的vscode编译好的class路径,一般是traget/classes)"
    ],
    "mainClass": "JavaTester",
    "args": ""
},

PS: How to automatically compile and generate classes?

Generally, the eclipse method is used by default, which is the .classpath file in the project directory.

How to configure this file, please Baidu.

PS: Note that it is the project directory, not the vscode workspace directory.

The above is the detailed content of What to do if vscode debugging cannot load the class. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn