Fork me on GitHub
#graalvm
<
2022-06-01
>
brightraven09:06:31

Hmmm, I am missing out something over here. I have a small program that I'm trying to pack into an uberjar and AOT compile with GraalVM native image.

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.11.1"}
        com.cognitect.aws/api {:mvn/version "0.8.539"}
        com.cognitect.aws/endpoints {:mvn/version "1.1.12.186"}
        com.cognitect.aws/s3 {:mvn/version "820.2.1083.0"}
        clojure.java-time/clojure.java-time {:mvn/version "0.3.3"}
        techascent/tech.ml.dataset {:mvn/version "6.085"}
        org.apache.parquet/parquet-hadoop {:mvn/version "1.12.0"
                                           :exclusions [org.slf4j/slf4j-log4j12]}
        org.apache.hadoop/hadoop-common {:mvn/version "3.3.0"
                                         :exclusions [org.slf4j/slf4j-log4j12]}
        org.apache.hadoop/hadoop-mapreduce-client-core {:mvn/version "3.3.0"
                                                        :exclusions [org.slf4j/slf4j-log4j12]}
        scicloj/tablecloth {:mvn/version "6.076"}
        cnuernber/dtype-next {:mvn/version "9.027"}
        criterium/criterium {:mvn/version "0.4.6"}
        environ/environ {:mvn/version "1.2.0"}
        com.github.clj-easy/graal-build-time {:mvn/version "0.0.3"}}
 
 :resource-paths ["resources"]
 :aliases
 {:run-m {:main-opts ["-m" "dalgo.qaf"]}
  :run-x {:ns-default dalgo.qaf
          :exec-fn -main
          :exec-args {:name "Clojure"}}
  :env/dev {:extra-paths ["dev"]}
  :test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}
  :runner
  {:extra-deps {com.cognitect/test-runner
                {:git/url ""
                 :sha "b6b3193fcc42659d7e46ecd1884a228993441182"}}
   :main-opts ["-m" "cognitect.test-runner"
               "-d" "test"]}
  :build {:deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.8.0" :git/sha "9bd8b8a"
                  ;; omits deps-deploy dependency:
                  :deps/root "slim"}}
          :ns-default build}
   :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
            :exec-fn hf.depstar/uberjar
            :exec-args {:aot true}}
  ;; build a jar (library):
  :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
        :exec-fn hf.depstar/jar
        :exec-args {}}}}
I had been using build-clj to build an uberjar but I kept hitting the same problem in the graalvm generated executables:
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
So I switched back to running depstar -X:uberjar with :compile-ns ':all' which compiles my namespaces. I generate my native image with the following command line invocation
native-image -cp app.jar -jar app.jar -H:Name=app -H:Path=native -H:+ReportExceptionStackTraces -J-Dclojure.spec.skip.macros=true -J-Dclojure.compiler.direct-linking=true -J-Xmx10G -J-Dtech.v3.datatype.graal-native=true --no-fallback --native-image-info 
and then.... nothing, just the same error.
[billy@glorfindel qaf]$ native/app
Exception in thread "main" java.lang.ExceptionInInitializerError
	at clojure.main.<clinit>(main.java:20)
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
	at clojure.lang.RT.load(RT.java:462)
	at clojure.lang.RT.load(RT.java:424)
	at clojure.lang.RT.<clinit>(RT.java:338)
	... 1 more
Clearly I'm forgetting something pretty basal -- I'd appreciate any help on tracking down what I've forgotten to do.

brightraven09:06:05

java -jar app.jar
works fine, I get the clojure prompt no problem.

brightraven10:06:22

I have added graal-build-time to the project dependencies and it is bundled into the uberjar. But I see now that I have version 0.0.3(??) instead of 0.1.4; I'll try to up that first.

brightraven10:06:19

Oh yeah, that makes a difference. I see the actual prompt 😄 Thanks

🎉 3