17

Using VS Code for Java debugging, there must be projectNamedefined in the launch.json file for using the watch-window while debugging.

How to determine and/or define the name of the Java project?

I always get the error message:

Failed to resolve classpath: The project '??' is not a valid java project.

Here my launch.json extract:

        "type": "java",
        "name": "Debug (Launch)-Application<foo>",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopOnEntry": false,
        "mainClass": "FooClass",
        "args": "",
        "projectName": "??",
        "windows": {
            "classPaths": [
                "%CLASSPATH%","C:\\JUnit\\junit-4.12.jar", "C:\\JUnit\\hamcrest-junit-2.0.0.0.jar", "."
            ]
         }
2
  • There might be a bug with Java Test Runner. Solution: create a Java project with Eclipse and open it with VS Code. Important are the .project and .classpath files. (or use templates and work with copies of them)
    – bambino307
    Jan 31, 2018 at 20:54
  • Try to remove "projectName". Just "mainClass" should work.
    – Alex 75
    Aug 11, 2019 at 18:36

6 Answers 6

9

For Maven projects(at least) you can find the project names at the bottom of the vscode sidebar under MAVEN PROJECTS.

enter image description here

You can also look for .project files inside your projects. The projectName is there in the name attribute.

enter image description here

*I'm not expert on this at all, but I was struggling with this too, so I hope it can help someone else!

1
  • 2
    What to do if I have multiple web projects in the workspace? Should I put in entry project only?
    – Harshal
    Jun 3, 2019 at 14:29
4

If you are using the extension Debugger for Java (https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug), then the projectName is the name of the directory that your project is in.

For instance, if your project looks like the following.

my-project/
  src/
    main/
      java/
        myproject/
          Application.java
  .project
  pom.xml

Then projectName = "my-project"

0
4

The VSCode contains JAVA PROJECTS on the sidebar. I am using SSH plugin to connect to a machine where the project actually resides (VS Code runs locally) so the name of the java project is my name and some hash to it

VSCodeSideBar

After adding the hash "_c4503cca" to the projectName in launch.json, the watches in debug mode work fine.

1
4

i was going crazy trying to figure out why the update i made to .project and pom.xml didn't change the project name in vs code...

  1. edit projectDescription / name in .project

  2. edit artifactId in pom.xml

  3. here's what i did to get it to reload and show the updated project name:

update project name

https://github.com/Microsoft/vscode-java-debug/blob/main/Troubleshooting.md#failed-to-resolve-classpath

0

Stumbled upon this thread while searching for "Failed to resolve classpath: The project '??' is not a valid java project.". In my case the culprit was rather silly. I have multiple projects within one parent folder and one common build.gradle in the root folder. E.g.:

parent/
├── abc/
├── def/
├── build.gradle
└── settings.gradle

The "??" in my case was referring to one of the projects, be it abc. After modifying settings.gradle in root folder to contain the following line problem seems to be gone.

rootProject.name = 'gat'
0

setting projectName: "" works

otherwise, go to the Java Projects -> right click on project -> Reveal in Explorer and it shows the folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.