2

I've a clojure project with deps.edn which uses the library clj-async-profiler

My main function in the project contains the below code -

(ns com.myns.cli
  (:gen-class)
  (:require
   [clj-async-profiler.core :as profiler]
   [clj-async-profiler.ui :as profiler.ui]))

(set! *warn-on-reflection* true)

(defn -main [& args]
      (profiler/serve-ui 8074)
      (.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable profiler.ui/stop-server))
  ;;(run config-file))

The java application is started with the command java -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/jdk.attach=ALL-UNNAMED -Djdk.attach.allowAttachSelf -cp myapp.jar

  WARNING: package jdk.attach not in java.base
  Exception in thread "main" java.lang.ExceptionInInitializerError
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Unknown Source)
      at java.base/java.lang.Class.forName(Unknown Source)
      at clojure.lang.RT.classForName(RT.java:2209)
      at clojure.lang.RT.classForName(RT.java:2218)
      at clojure.lang.RT.loadClassForName(RT.java:2237)
      at clojure.lang.RT.load(RT.java:449)
      at clojure.lang.RT.load(RT.java:424)
      at clojure.core$load$fn__6908.invoke(core.clj:6162)
      at clojure.core$load.invokeStatic(core.clj:6161)
      at clojure.core$load.doInvoke(core.clj:6145)
      at clojure.lang.RestFn.invoke(RestFn.java:408)
      at clj_async_profiler.core__init.load(Unknown Source)
      at clj_async_profiler.core__init.<clinit>(Unknown Source)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Unknown Source)
      at java.base/java.lang.Class.forName(Unknown Source)
      at clojure.lang.RT.classForName(RT.java:2209)
      at clojure.lang.RT.classForName(RT.java:2218)
      at clojure.lang.RT.loadClassForName(RT.java:2237)
      at clojure.lang.RT.load(RT.java:449)
      at clojure.lang.RT.load(RT.java:424)
      at clojure.core$load$fn__6908.invoke(core.clj:6162)
      at clojure.core$load.invokeStatic(core.clj:6161)
      at clojure.core$load.doInvoke(core.clj:6145)
      at clojure.lang.RestFn.invoke(RestFn.java:408)
      at clojure.core$load_one.invokeStatic(core.clj:5934)
      at clojure.core$load_one.invoke(core.clj:5929)
      at clojure.core$load_lib$fn__6850.invoke(core.clj:5976)
      at clojure.core$load_lib.invokeStatic(core.clj:5975)
      at clojure.core$load_lib.doInvoke(core.clj:5954)
      at clojure.lang.RestFn.applyTo(RestFn.java:142)
      at clojure.core$apply.invokeStatic(core.clj:669)
      at clojure.core$load_libs.invokeStatic(core.clj:6017)
      at clojure.core$load_libs.doInvoke(core.clj:6001)
      at clojure.lang.RestFn.applyTo(RestFn.java:137)
      at clojure.core$apply.invokeStatic(core.clj:669)
      at clojure.core$require.invokeStatic(core.clj:6039)
      at identity_check.cli$loading__6789__auto____149.invoke(cli.clj:1)
      at identity_check.cli__init.load(Unknown Source)
      at identity_check.cli__init.<clinit>(Unknown Source)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Unknown Source)
      at java.base/java.lang.Class.forName(Unknown Source)
      at clojure.lang.RT.classForName(RT.java:2209)
      at clojure.lang.RT.classForName(RT.java:2218)
      at clojure.lang.RT.loadClassForName(RT.java:2237)
      at clojure.lang.RT.load(RT.java:449)
      at clojure.lang.RT.load(RT.java:424)
      at clojure.core$load$fn__6908.invoke(core.clj:6162)
      at clojure.core$load.invokeStatic(core.clj:6161)
      at clojure.core$load.doInvoke(core.clj:6145)
      at clojure.lang.RestFn.invoke(RestFn.java:408)
      at clojure.lang.Var.invoke(Var.java:384)
      at clojure.lang.Util.loadWithClass(Util.java:251)
      at com.myns.cli.<clinit>(Unknown Source)
  Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
      at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Unknown Source)
      at java.base/java.lang.Class.forName(Unknown Source)
      at clojure.lang.RT.classForName(RT.java:2209)
      at clojure.lang.RT.classForNameNonLoading(RT.java:2222)
      at clj_async_profiler.util.jdk11__init.load(Unknown Source)
      at clj_async_profiler.util.jdk11__init.<clinit>(Unknown Source)
      ... 56 more
  

How can I fix this error? I can see jdk.attach module belongs to java.base in java documentation. Why I get the warning WARNING: package jdk.attach not in java.base in the console ?

Note:

Below are the java version details -

java --version
openjdk 21.0.3 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

Also --list-modules commands returns -

$java --list-modules
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Also, I use docker image eclipse-temurin:21-jre-jammy if it helps

7
  • "I can see jdk.attach module belongs to java.base in java" -- No, the jdk.attach module is separate from the java.base module. A module can require another module, but it doesn't "belong" to any other module. The graph in the documentation says jdk.attach requires java.base. Also, you're treating jdk.attach like a package instead of a module. A module is made up of one or more packages. What happens if you instead use --add-modules jdk.attach to your command? Commented Jul 3, 2024 at 21:49
  • When I add --add-modules jdk.attach I get exception ` Error occurred during initialization of boot layer 1 java.lang.module.FindException: Module jdk.attach not found` Commented Jul 3, 2024 at 21:53
  • 1
    java --list-modules | grep jdk.attach returns [email protected] Commented Jul 3, 2024 at 21:55
  • 1
    @Slaw I'm wrong. It is not present in the java. Not use why eclipse-temurin:21-jre-jammy doesn't have this module Commented Jul 3, 2024 at 22:11
  • 2
    Might be because it's supposedly just a JRE and not a JDK (which is a JRE with development tools included)? Commented Jul 3, 2024 at 23:39

1 Answer 1

0

The problem is indeed the Docker image eclipse-temurin:21-jre-jammy. clj-async-profiler requires JDK to work. Using e.g. eclipse-temurin:21-jdk-noble should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.