skip to Main Content

I have a Java program that I have been using for several months now that generates excel surveys. I an using Maven as my Java build in VS Code. For some reason, starting today, as soon as I opened the project in VS Code, I got this error:

The project was not built since its build path is incomplete. Cannot find the class file for java.lang.String. Fix the build path then try building this project

In addition to this error, I have over 100 other errors like "java.lang.Object". cannot be resolved. What could have caused this problem given that I have not touched this program or the class path or pom.xml in the last few days, and how can the issue be resolved?

I have done a lot of research online, and most people say to change the build path on my project by doing this: "Right click on the project name –> Open Properties –> Java Build Path –> Add Jars"

Essentially this article: the project was not built since its build path is incomplete vscode

The problem is, I am on Mac, and there is no way to "Open Properties", or if there is I cannot find it. Can someone provide similar steps to that for Mac?

Because I was curious I opened the folder for the Java project on another computer (also mac) and it worked perfectly fine which seems so strange.

I also tweaked my pom.xml file and when I try to update it I get this error:

Full component analysis cannot be performed until the Pom is valid.`

I tried to include my pom.xml file in this post, but it was flagged as spam.

I don’t think there is anything that should make this pom.xml file invalid since, like I said, I opened this project on another computer and it worked completely fine.

3

Answers


  1. I had the same issue today, coincidentally after a VSCode update, after downgrading extensions, downgrading VSCode. I think it turned out that my JAVA_HOME was not set and as such the whole thing blew up. I can’t promise because I want on a rage trying to solve.

    Login or Signup to reply.
  2. Had the same problem today. It’s a problem with your JAVA_HOME path.

    You’ll have to see what version of JAVA you have installed via the terminal (on a mac):

     java —-version
    

    Assuming you’re on version 16.0.1, your JAVA_HOME path should look something like this (check the directory exists)

    /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home/
    

    Then it should be a matter of exporting JAVA_HOME in your .zprofile file, using:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home/
    

    You should then restart VS Code and Java should be up and running again.

    Also check out this useful answer if necessary:
    How to set JAVA_HOME environment variable on macOS?

    Login or Signup to reply.
  3. This is probably this issue ticket: Extension version 1.22.0 cannot find OpenJDK on macOS
    #3287
    . If I understand correctly, the cause is explained here by one of the maintainers, Jinbo Wang:

    Looks like Java extension detects /usr as ‘JavaSE-17’ home path, this should be a bug

    The timing of this "suddenly" here also lines up perfectly with the release of version 1.22 of the Java extension, which is what that issue ticket is about (combined with it being a macOS + OpenJDK thing).

    The issue is purportedly fixed in version 1.22.1 of the Java extension (source). Quoting Fred Bricon:

    If you still see JDK class errors after upgrading to 1.22.1, please open Command Palette and run Java: Clean Java Language Server Workspace.

    Note: It’s also purportedly fixed in version 1.23.2023091313, which has been released in the pre-release channel (source). If you don’t want to update for some reason, other users had previously found success by rolling back to version 1.21.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search