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

Error: Could not find or load main class launch.json #33

Closed kmuthukrishnan closed 7 years ago

kmuthukrishnan commented 7 years ago

Hi @DonJayamanne ,

I am trying to use your plugin to debug my java code on vs. I have made changes to java path and tasks.json as you indicate When I try to run the debugger, Iam now getting the error **Error: Could not find or load main class launch.json**.

How do I fix this? Please help. Thanks

jakoberzar commented 7 years ago

@kmuthukrishnan, in case you haven't solved it by now, that's usually the case when you run any vscode debugger in a wrong file - your selected file was launch.json, and the debugger could not figure out how to debug it. Just select (open) the .java file that you want to debug and start debug.

DonJayamanne commented 7 years ago

@kmuthukrishnan would you like me to add you as a contributor to this repo?

viniciuscr commented 7 years ago

I had the similar problem. In your case you are running the debug from the launch.json and by default it is expected that you are with the main class open and active. But for me, just open the file didn´t solve the problem The solution was to edit the launch.json something like this:

{
            "name": "Java",
            "type": "java",
            "request": "launch", 
            "sourcePath": [
               "${workspaceRoot}/src/" 
            ],
            "jdkPath": "C:\\Program Files\\Java\\jdk1.8.0_121\\bin",
            "stopOnEntry": true,
            "cwd": "${fileDirname}",
            "startupClass": "main.Main",
            "preLaunchTask": "build",
            "options": [
                "-classpath",
                "${workspaceRoot}/target/classes"
            ]
        },

the startupClass:"${fileBasename}" do not work if the class is inside a package. Also, set sourcePath, Or may it won´t find your .java files. As I am using maven, I have to set "options": [ "-classpath", "${workspaceRoot}/target/classes" ] otherwise it won´t find my .class files.

kmuthukrishnan commented 7 years ago

Thanks @Vinicius CR. Will try and revert.

On Apr 25, 2017 7:42 PM, "Vinicius CR" notifications@github.com wrote:

I had the same problem. The solution was to edit the lauch.json something like this:

{ "name": "Java", "type": "java", "request": "launch", "sourcePath": [ "${workspaceRoot}/src/" ], "jdkPath": "C:\Program Files\Java\jdk1.8.0_121\bin", "stopOnEntry": true, "cwd": "${fileDirname}", "startupClass": "main.Main", "preLaunchTask": "build", "options": [ "-classpath", "${workspaceRoot}/target/classes" ] },

the startupClass:"${fileBasename}" do not work if the class is inside a package. Also, set sourcePath, Or may it won´t find your .java files. As I am using maven, I have to set "options": [ "-classpath", "${workspaceRoot}/target/classes" ] otherwise it won´t find my .class files.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/33#issuecomment-297043139, or mute the thread https://github.com/notifications/unsubscribe-auth/AE2PvpsrO4A2nUqeSqn9x9mzBVB7B6qSks5rzf9fgaJpZM4M2mXw .

faustinoaq commented 7 years ago

README has been update, please take a look