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?

0
13 comments

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? 

0

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?

0

I have no run configurations at all, this happens after Build -> Build Project.

0

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. 

0

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.

0
Avatar
Permanently deleted user

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.

0
Avatar
Permanently deleted user

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?

0
Avatar
Yaroslav Bedrov

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.

0
Avatar
Permanently deleted user

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?

0
Avatar
Yaroslav Bedrov

I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-296485/Intellij-cannot-find-jdkjfr-classes

Please follow it for updates.

1

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


 

 

0

Please sign in to leave a comment.