vscode-java: Project does not build due to build path being incomplete
None of my Java projects are being built properly by the language server.
All my projects are failing, even previously working projects
Fundamentally, I’m getting JRE errors such as The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
.
I’m unable to open standalone Java files, vanilla Java projects and packages, or Maven projects properly.
Here are some things I’ve tried:
- Cleaned and restarted the language server workspace multiple times.
- Set up the runtimes properly according to the guide.
- Set
JAVA_HOME
,java.home
to jEnv symlinks.jenv/versions/14.0
and directly to the JDK installations themselves/usr/local/Cellar/openjdk/14.0.1/
. - Repeated the above steps with Java 11 and Java 14.
- Repeated the above steps with Java 11 Homebrew Cask installation of OpenJDK
/Library/Java/JavaVirtualMachines/...
- Full wipe of VSCode and reinstalled everything, with the same results.
Additional Informations
I’m using jenv
to manage my JDKs, and I’ve enabled the export
and maven
plugins. Compilation with javac
and running with java
works just fine.
Environment
- Operating System: macOS 10.15.6
- JDK version: 11.0.8, 14.0.1
- Visual Studio Code version: 1.48.2
- Java extension version: 0.65.0
Steps To Reproduce
- Open a new
.java
file and define a class.
Log files
redhat.java/client.log.2020-08-26
client.log
Current Result
Plugin is unable to find JRE classes which causes compilation errors for the server.
Expected Result
Plugin should be able to link to JRE classes and compile properly, providing Intellisense without any errors.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 21 (2 by maintainers)
In VSCode open Command Palette: Java: Clean Java Language Server Workspace -> then restart VSCode fixed this issue for me
I had the same problem, and I’m also using Homebrew-installed OpenJDKs. After some trial and error, finally I found the solution: just point OpenJDK to
/usr/local/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home
instead of/usr/local/opt/openjdk@11
. So the Java runtime configuration looks like this:Note: It’s recommended to point OpenJDK to
/usr/local/opt/openjdk@11
instead of/usr/local/Cellar/openjdk@11/11.0.5
because the former is always a symlink to the latest version of the formula (in this case,/usr/local/Cellar/openjdk@11/11.0.5
) and will survive future minor and patch version updates.Note 2: If you are just using
java
,javac
,jar
or other binaries from the the OpenJDK on the command line, you can justexport JAVA_HOME=/usr/local/opt/openjdk
but for VS Code to make full use of the OpenJDK you need to point it to/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home
because that’s where thejmods
directory resides.@bryanmylee Could you try the following:
It’s worked for me add this two props on my settings.json:
In my case the resolution was something different. My project needs Java 8 and
pom.xml
has this.I have both JDK 8 and 15 installed and VS Code correctly detects both.
However, when the project was opened in VS Code it did not choose the JDK correctly to compile the project. I had to manually fix this.
After that the project compiled fine and the
The project was not built since its build path is incomplete
error went away.It is worth noting that VS Code doesn’t have this problem if you specify the JDK version using properties:
We are switching to this from setting configuration of the
maven-compiler-plugin
.@luangong Thanks, that solved my issue. I had to do this:
The above also worked for me. Does anyone know why this error suddenly occurred sometime late yesterday (UTC/GMT +2 hours)?
Thanks for this! Like many other people, my project builds fine on the command line but the Redhat plugin trips over it. Setting the properties helped me.