Why is my build path suddenly incomplete for my java project in VS Code?
Asked Answered
B

3

5

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.

Botulinus answered 12/9, 2023 at 19:4 Comment(0)
A
4

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.

Atomism answered 14/9, 2023 at 8:12 Comment(0)
W
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?

Wrecker answered 13/9, 2023 at 14:59 Comment(2)
At first it showed that I didn't have any version of Java (I already had OpenJDK from Eclipse installed), so I had to reinstall the JDK and after that it already showed me the version. I then did the export in .zprofile, reopened vscode and Java worked again. Your answer was too helpful.Warila
I find it a curiosity how this helps. If you can run java --version, then it means java can already be resolved (presumably from the PATH). Or phrased differently, how could you run java --version if your java bin directory is not already in the PATH?Atomism
E
0

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.

Exequatur answered 13/9, 2023 at 13:13 Comment(1)
For me, I had to add my java location to the settings.json file, specifically adding the line: "java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home"Nasty

© 2022 - 2024 — McMap. All rights reserved.