Search code examples
javaspringspring-bootmaven

VS Code ERROR: The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object


I tried running my Spring boot project when I opened VS code then I saw this error. I have been using Java for some months now and this is the first time I am seeing this error.

My previous java projects have stopped running due to this error also.

Is there a possible fix to this? screenshot of error message


Solution

  • Fixed. I was able to solve this error with the process below:

    1. run java --version in terminal to know your jdk version
    2. cd /Library/Java/JavaVirtualMachines
    3. /usr/libexec/java_home -V
    4. Choose:
    • For Bash:
    echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/your-java-17-version' >> ~/.bash_profile
    source ~/.bash_profile
    
    • For Zsh:
    echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/your-java-17-version' >> ~/.zshrc
    source ~/.zshrc
    
    1. echo $JAVA_HOME

    2. Go to your project directory and run: mvn clean install

    3. In VSCode, go to Command Palette > Clean Java Language Server Workspace