Intellij cannot find jdk.jfr classes
Answered
I have a project which uses JFR classes from the jdk.jfr package. Command line maven build works fine, and the editor in Intellij is also able to resolve the jdk.jfr classes with any problem. But, building the maven project internally in Intellij results in the error "java: package jdk.jfr does not exist". Is there any trick to help Intellij find them?
Please sign in to leave a comment.
Is it possible to share a sample project?
Please also take a screenshot of the run configuration you are using. Is it "Maven", or "Application" run configuration?
Hi, the project is https://github.com/apache/camel and the subcomponent compents/camel-jfr exhibits the problem.
Is this the config you are interested in?
I mean run configuration: https://i.imgur.com/OpZCjI0.png
I have no run configurations at all, this happens after Build -> Build Project.
May you show the Maven tool window (tab on the right of your screenshot)
Do you see jfr classes in dependencies?
Try reimporting the project if no. Invalidating caches (File | Invalidate caches and Restart) could also help.
Hi Konstantin, no I don't see the jfr classes in the maven dependencies, but to be fair I don't see other JDK dependencies like java.lang or java.util, either. Invalidate cache and reimport has had no effect.
Ticking this checkbox should help:
https://i.imgur.com/0pqeSA4.png
I (and my entire team) are getting the same issue. While delegating the build to Maven obviously works, having to perform a full maven install before running any test really isn't a way forward. I've attached some screenshots that show that there really shouldn't be any issues finding JFR libraries. We're running the latest version of IntelliJ, 2022.1.2 Ultimate.
Interestingly when using JDK 8, the build works as expected. It's only when running with JDK 11 that we're seeing a problem. I noticed that in JDK 11, IntelliJ indicates (incorrectly) that the JFR features were introduced in Java 9? We're targeting Java 8 byte-code, so this may be related to the issue?
Hello,
What do you mean by "IntelliJ indicates (incorrectly) that the JFR features were introduced in Java 9"? I tried to build "https://github.com/apache/camel" project on my side and don't get build errors.
Camel moved to targeting JDK 11 byte code from version 3.15 onwards. If you checkout the branch camel-3.14.x (which targets OpenJDK 1.8 byte code), you should be able to replicate the fault when you attempt to build the module camel-jfr using IntelliJ's native build process (i.e. not delegating the build to Maven)
I've verified that the fault occurs when building that branch with OpenJDK 11.0.15. I haven't tested with newer major version releases of OpenJDK, but changing the Project SDK to an OpenJDK 1.8 installation will allow the module to be built as expected.
Given that Maven is able to build the project correctly even using an OpenJDK 11 toolchain, the expected behaviour is that IntelliJ should be able to do it too.
As I mentioned earlier, I suspect that this is related to JFR being marked as being introduced in Java 9?
I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-296485/Intellij-cannot-find-jdkjfr-classes
Please follow it for updates.
I found the behavior for "jfr not found even editor can access it". Suppose we have selected 'use module output path' at Project Settings/Modules/Paths. At this point there is authoritative place where the compiler's JDK must be changed. It is
Project Settings/Modules/project dependencies tab.
Also now the effective language level is set at:
Project Settings/Modules/sources