grafana/JPProf

I cannot run JPProf with JDK 8

Closed this issue · 6 comments

Hello,

It seems, that you pushed the library to maven repo with JDK 11 target.

jpprof-0.1.0/jpprof$ javap -verbose PprofHttpHandler | grep "major"
Warning: File ./PprofHttpHandler.class does not contain class PprofHttpHandler
  major version: 55

When I try to run an example with JDK 8, I got the following error:

$ java -version
openjdk version "1.8.0_333"
OpenJDK Runtime Environment (build 1.8.0_333-b02)
OpenJDK 64-Bit Server VM (build 25.333-b02, mixed mode)
JPProf/examples/springboot/src/main/java/com/example/springboot/PprofController.java:11: error: cannot access jpprof.CPUProfiler
import jpprof.CPUProfiler;
             ^
  bad class file: /home/user/.gradle/caches/modules-2/files-2.1/com.grafana/jpprof/0.1.0/701850efd445118005e300aaa9efd4b1424910d0/jpprof-0.1.0.jar(jpprof/CPUProfiler.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

I think, you pushed the library to maven before this change 290f9a5#diff-655a69127303f6948c0b150902436756156ec7f82640e994c1f552cbdec5bbceL11-L12

If you build the project and use the artifact do you have the same issue ? I thought I used the latest commit when I pushed.

@cyriltovena yes, if I build the library locally, everything works fine with it with JDK 8.

hi, I downloaded the jar package from maven central,https://mvnrepository.com/artifact/com.grafana/jpprof/0.1.0
and verify the class file version
jar -xf jpprof-0.1.0.jar
file jpprof/CPUProfiler.class

and the result output
jpprof/CPUProfiler.class: compiled Java class data, version 55.0 (Java SE 11)

the package in maven built for JDK11+

Yes I built it using my machine (Java 11) does this means I need to downgrade to 8 ? happy to deploy a 0.1.1 today if needed let me know.

EDIT: We're working on it.

sorry for delay..

Basically, there a few options here, what you can do:

  1. Start building the jar from github actions. As I can see, you have already implemented it.
  2. Use Source and Target options with jdk11, like https://www.baeldung.com/java-source-target-options
  3. Use gradle toolchain, which allows to use different version of java during build https://docs.gradle.org/current/userguide/toolchains.html

By default, I would suggest to go to option 1. However, something it is not possible to have maven credentials in github, in this case you can use something else.

P.S. If you are not aware, check https://sdkman.io/ . It is a great tool, which allows you to have multiply JDK versions, and switch them in 1 second, like sdk use java 17.0.4.1-librca

Thanks @Hixon10! So we went for option 1, as you say, in the end. The library is now built and published via GH actions. Latest version (0.1.4) should work fine with jdk8, so closing the ticket now.