简体   繁体   English

添加更多程序包后,Visual Studio代码无法找到或加载主类

[英]Visual Studio code could not find or load main class after adding more packages

I started using VS Code recently because I find it much cleaner and faster than eclipse but I am having extreme difficulty getting it to run stuff. 我最近开始使用VS Code,是因为我发现它比Eclipse更干净,更快捷,但是要使其运行起来却非常困难。 Currently I am trying to just start a new project so I add a few classes, put them into packages and try to just run a few basic things but it fails to load for any class. 目前,我正试图开始一个新项目,所以我添加了一些类,将它们放入程序包中,并尝试仅运行一些基本的东西,但是对于任何类都无法加载。 My directory structure is as such : https://i.imgur.com/7auMNnI.png and my launch.json is 我的目录结构是这样的: https ://i.imgur.com/7auMNnI.png而我的launch.json是

"version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)-Path",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopOnEntry": false,
            "mainClass": "simulation.utils.Path",
            "args": ""
        },
        {
            "type": "java",
            "name": "Debug (Launch)-Route",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopOnEntry": false,
            "mainClass": "simulation.utils.Route",
            "args": ""
        },
        {
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 0
        }
    ]
}

However i can not get it to launch any of these. 但是我无法启动它们。 Previously I had it with just one class in its own package and it worked fine. 以前,我在自己的程序包中只有一个类,所以效果很好。 Upon adding more packages it broke everything. 添加更多软件包后,它破坏了一切。 From looking at the issue tracking on the git for VSCode it seems that package structure didn't function at one point but has been fixed so this is clearly something I am doing wrong. 从VSCode的git上的问题跟踪来看,似乎包结构没有在某一时刻起作用,但已得到修复,因此这显然是我做错的事情。

I know the question is old, but for anyone else who may be getting the same issue I found that adding a "sourcePaths" reference in launch.json resolved the issue. 我知道这个问题很旧,但是对于其他可能遇到相同问题的人,我发现在launch.json中添加“ sourcePaths”引用可以解决此问题。 eg 例如

"configurations": [
    {
        "type": "java",
        "name": "Debug (Launch)",
        "request": "launch",
        "sourcePaths": [
            ".",
            "${fileDirname}"
        ],
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopOnEntry": false,
        "mainClass": "MainProg",
        "args": ""
    },

For me it was a weird bug with the code runner extension. 对我来说,这是代码运行器扩展的一个奇怪的错误。 Clicking the (VSCode native) Run command above the main method works fine. 单击main方法上方的(VSCode本机)运行命令可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM