Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception with openjdk #78

Open
devnewton opened this issue Oct 28, 2024 · 4 comments
Open

Exception with openjdk #78

devnewton opened this issue Oct 28, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@devnewton
Copy link

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/management/OperatingSystemMXBean
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Unknown Source)
	at java.base/java.lang.Class.getDeclaredMethod(Unknown Source)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
@theobisproject
Copy link
Contributor

Is it possible to get more information about the JDK you observed this exception on? The following would help greatly:

  • Distribution (Oracle, Temurin, Amazon Corretto)
  • Version (11, 17, 21, ...)
  • Used OS

Please not that the not found class is platform specific and might not be available in the OS JDK combination.

@devnewton
Copy link
Author

I use a Docker image with openjdk and maven ( maven:3.9.9-eclipse-temurin-17 https://github.com/carlossg/docker-maven/blob/8cfe24baffa5b250f7bb2d31ce233fc28f3c4f20/eclipse-temurin-17/Dockerfile ) on Ubuntu.

The full java distribution information : OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (17.0.13+11, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64).

@adelnoureddine adelnoureddine added the help wanted Extra attention is needed label Nov 13, 2024
@adelnoureddine
Copy link
Member

Hi, it may be possible that OperatingSystemMXBean class isn't available in your Java distribution in Docker.

@theobisproject
Copy link
Contributor

I failed to reproduce your issue with the JDK base image used in the Dockerfile you linked.

Running the JDK on a bare metal Ubuntu 24.04 worked as expected

$ sudo /opt/jdk-17.0.13+11/bin/java -javaagent:target/joularjx-3.0.0.jar -version
17/11/2024 09:18:51.546 - [INFO] - +---------------------------------+
17/11/2024 09:18:51.546 - [INFO] - | JoularJX Agent Version 3.0.0    |
17/11/2024 09:18:51.546 - [INFO] - +---------------------------------+
17/11/2024 09:18:51.560 - [INFO] - Results will be stored in joularjx-result/56857-1731831531558/
17/11/2024 09:18:51.567 - [INFO] - Initializing for platform: 'linux' running on architecture: 'amd64'
17/11/2024 09:18:51.574 - [INFO] - Please wait while initializing JoularJX...
17/11/2024 09:18:52.581 - [INFO] - Initialization finished
17/11/2024 09:18:52.581 - [INFO] - Started monitoring application with ID 56857
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode, sharing)
17/11/2024 09:18:53.632 - [INFO] - JoularJX finished monitoring application with ID 56857
17/11/2024 09:18:53.632 - [INFO] - Program consumed 5.54 joules
17/11/2024 09:18:53.635 - [INFO] - Energy consumption of methods and filtered methods written to files

This means the JDK should not throw the NoClassDefFoundError.

Running in a Docker container exits early for me since the RAPL interface is not available in the container

17/11/2024 08:30:37.340 - [INFO] - Could not locate config.properties, will use default values
17/11/2024 08:30:37.341 - [INFO] - +---------------------------------+
17/11/2024 08:30:37.341 - [INFO] - | JoularJX Agent Version 3.0.0    |
17/11/2024 08:30:37.341 - [INFO] - +---------------------------------+
17/11/2024 08:30:37.353 - [INFO] - Results will be stored in joularjx-result/1-1731832237351/
17/11/2024 08:30:37.361 - [INFO] - Initializing for platform: 'linux' running on architecture: 'amd64'
17/11/2024 08:30:37.361 - [SEVERE] - Platform not supported. Exiting...

The Dockerfile I used

FROM eclipse-temurin:17-jdk

RUN apt-get update \
  && apt-get install -y ca-certificates curl git openssh-client --no-install-recommends \
  && rm -rf /var/lib/apt/lists/*

COPY target/joularjx-3.0.0.jar /root/

CMD ["java", "-javaagent:/root/joularjx-3.0.0.jar", "-version"]

Have you done any specific mounts for your Docker container to be able to use the RAPL interface? Anything changed in the properties file to get the agent to try and initialize the OperatingSystemMXBean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants