Compilation error in VSCode:
The import javax.annotation.PostConstruct cannot be resolved
Looking at the effective pom, the following dependency is present:
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
Works for me. You can try to right-click on your project's pom and try to "update project configuration", if that doesn't work then call the "Clean the Java language server workspace" command
Hi @fbricon, thank you for the prompt reply.
I did the update and clean... but nothing.
the following works:
May I collect more info from my env?
See https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting on how collect logs
Hi @fbricon here the log.
The only error that I see is the following:
!ENTRY org.eclipse.jdt.ls.core 4 0 2019-04-09 23:21:57.341
!MESSAGE
!STACK 0
org.eclipse.jface.text.BadLocationException
at org.eclipse.jface.text.ListLineTracker.getLineOffset(ListLineTracker.java:197)
at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:160)
at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:876)
(...)
Does it help?
Maybe you are interested even to other files in the directory:
Hi @fbricon, any hints? Did you have the chance to look into the logs?
I'm quite surprised that you cannot reproduce the error. I have installed everything from scratch, cleaning all the user data (.config, etc). But I run always in the same problem.
Which OS and JVM are you using?
Thank you
@dmarrazzo could you try the following:
"java.home": "/usr/lib/jvm/java-1.8.0-openjdk/",
to VS Code settings
rm -rf /home/donato/.config/Code/User/workspaceStorage
Hello @snjeza, this solved the problem!
So the issue was due to a wrong javac (I suspect jdk11).
Thank you very much!
@dmarrazzo your server logs show you're using java.version=11.0.2. Alternatively, if you open vscode's developer tools, you'll see which JDK binary is used to launch the language server.
Some recent jdks cause some issues with some annotation processors, so it might be sometimes safer to use 1.8
Thank you @fbricon
My confusion was caused by the fact that alternative command admits two configuration for java and javac so I thought I was running 1.8 but the javac was actually on 11.
@snjeza Thank you so much! this fixed my issue too. Confirmed this also fixes unresolved dependencies in my Gradle sparkjava web app project (with Kotlin DSL). Must have been because I just switched from oracle's jdk 8 to OpenJDK 11, due to their changes in support. This also fixed up the Java Dependency Explorer extension and I can now see sparkjava and jetty jars listed under my project tree.
Most helpful comment
@dmarrazzo could you try the following:
to VS Code settings