oracle / javavscode

Java platform support for Visual Studio Code for full featured Java development (edit-compile-debug & test cycle)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run/Debug with launch.json configuration using "mainClass" fails with "internal error"

robaho opened this issue · comments

I am using vscode 1.83.1

I have a valid configuration, like:

        {
            "type": "jdk",
            "name": "Main",
            "request": "launch",
            "mainClass": "cff.package.main.Main",
            "args": "dev",
            "vmArgs": "-Dmy-services=etc/services/dev-services.properties -Dorg.jboss.logging.provider=jdk"
        },

but when I run it I get the attached:

image

I am only able to run things using Gradle tasks or the 'tooltip runner' as in:

image

I was able to narrow down the cause.

This fails if the launch.json specifies a mainClass attribute. This makes it impossible to use run/debug when a project contains multiple top-level entry points.

The only option that works is to go to the main class and use the Intellisense to run the class.

I'm also experiencing this problem. The workaround suggested above doesn't work for me either, since there's a custom build (see also #18).

I looked into this issue. Actually you need to provide absolute path to the mainClass. Please try using absolute path.

Example configuration:

{
    "version": "0.2.0",
    "configurations": [
    {
        "type": "jdk",
        "request": "launch",
        "name": "Main",
        "mainClass": "/Users/atalati/vscode-extension/testingProjects/simpleMavenProject/src/main/java/org/yourcompany/yourproject/SimpleMavenProject.java",
        "args": "dev",
        "vmArgs": ""
    }
    ]
}

Also, please can you update here if it worked or not?

@Achal1607 this worked for me -- thank you 🙏

Having a field called mainClass that expects a path to a source file is ... surprising. Renaming it to something like mainSourceFile might save users some frustration.

@Achal1607 Not sure this is a good solution - what if the launch.json file is checked in Git and shared between team members with different project directories? Not very portable.