DonJayamanne / javaVSCode

Extension for java development on VSCode (deprecated)
https://marketplace.visualstudio.com/items?itemName=donjayamanne.javaDebugger
MIT License
43 stars 29 forks source link

Failed to start the program, Error: spawn /bin/java ENOENT #59

Closed clankill3r closed 7 years ago

clankill3r commented 7 years ago

When I try to debug I get the following error:

Failed to start the program, Error: spawn /bin/java ENOENT

Platform OSX. The JAVA_HOME is set, if I echo $JAVA_HOME I get /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home (which exists).

My tasks looks like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "type": "shell",
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared"
    },
    "isBackground": true,
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "build",
            "command": "javac",
            "args": ["-g", "${file}"]
        }
    ]
}

and launch looks like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Java",
            "type": "java",
            "request": "launch",
            "stopOnEntry": true,
            "preLaunchTask": "build",                 // Runs the task created above before running this configuration
            "jdkPath": "${env:JAVA_HOME}/bin",
            "cwd": "${fileDirname}",
            "startupClass": "${fileBasenameNoExtension}",
            "classpath": [
                ".",
                "${fileDirname}"
            ],
            "args": []
        }
    ]
}

This is the code I try to run:

import java.util.ArrayList;

public class Test {

    public static void main(String[] args) {
        Test t = new Test();
        t.foo();
    }

    public void foo() {

        ArrayList<?> l = new ArrayList<>();
        ArrayList ll = new ArrayList<>();
        System.out.println("Foo!");
        System.out.println("Bar!");
        System.out.println("End!");
    }

}

(O yeah, the readme of this repository contains a lot of fields that are deprecated).

faustinoaq commented 7 years ago

(O yeah, the readme of this repository contains a lot of fields that are deprecated).

Yes, a better README is needed. :sweat_smile:

screenshot_20170802_104203

I don't know what is your issue, I was able to debug your java code with the config you show me.

On Linux JAVA_HOME is /usr/lib/jvm/default and works well. :sweat_smile:

clankill3r commented 7 years ago

In case it helps:

This is the terminal output:

> Executing task: javac -g /Users/doekewartena/Desktop/temp/VSCODE_tests/java/Test.java <

Terminal will be reused by tasks, press any key to close it.

faustinoaq commented 7 years ago

The terminal output show that your javac is working well.

Maybe you should replace "${env:JAVA_HOME}/bin" by an absolute path where bin folder is located.

clankill3r commented 7 years ago

Yeah that worked! Is that a bug in VSCode?

faustinoaq commented 7 years ago

Maybe, I don't know, my VSCode is working well with "${env:JAVA_HOME}/bin

faustinoaq commented 7 years ago

Yeah that worked!

ManushaBethelli commented 7 years ago

{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [

    {
        "name": "Java",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ]
    },
    {
        "name": "Java Console App",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ],
        "externalConsole": true
    }
]

}

Here is my launch.json. When I try to start debugger, it says Error: Could not find or load main class Authors Any thoughts ?

faustinoaq commented 7 years ago

Try replacing "jdkPath": "${env:JAVA_HOME}", by "jdkPath": "${env:JAVA_HOME}/bin",

ManushaBethelli commented 7 years ago

That was the initial generated thing and I did replace it to "jdkPath": "${env:JAVA_HOME}". With "jdkPath": "${env:JAVA_HOME}/bin", I see

screen shot 2017-09-19 at 10 37 29 pm
faustinoaq commented 7 years ago

Ok, try to use absolute path for JDK instead

ManushaBethelli commented 7 years ago

Tried that too. It goes back to my initial issue again :( Error: Could not find or load main class Authors

ManushaBethelli commented 7 years ago

Never mind. I think I have an issue with my Java file. Tried with a new one and that worked. Thanks for quick response.