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
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.
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):
Assuming you’re on version 16.0.1, your JAVA_HOME path should look something like this (check the directory exists)
Then it should be a matter of exporting JAVA_HOME in your .zprofile file, using:
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?
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:
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:
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.