Trying to compile a helloworld with https://github.com/taylorwood/lein-native-image and get
Error: Could not find or load main class graal_thing.core
Caused by: java.lang.ClassNotFoundException: graal_thing.core
after what appears to be a successful lein native-image
@kamuela Have you used :gen-class
in your main namespace?
have you specified the main ns in project.clj?
Hmm, I created this with lein new app
but
(defproject graal-thing "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "<http://example.com/FIXME>"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "<https://www.eclipse.org/legal/epl-2.0/>"}
:dependencies [[org.clojure/clojure "1.10.2-alpha1"]]
:main ^:skip-aot graal-thing.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}}
:plugins [[io.taylorwood/lein-native-image "0.3.1"]])
I think that line does what you've asked
And for further reference
➜ graal-thing lein run
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
PING!
PONG!
I do just realize there are some warnings when I run lein native-image
➜ graal-thing lein native-image
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
Compiling graal-thing.core
Build on Server(pid: 58122, port: 50139)
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] classlist: 878.30 ms, 2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (cap): 1,905.34 ms, 2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] setup: 2,186.43 ms, 2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (clinit): 170.72 ms, 2.65 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] analysis: 10,394.34 ms, 2.65 GB
Warning: Aborting stand-alone image build due to unsupported features
Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Build on Server(pid: 58122, port: 50139)
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] classlist: 80.53 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (cap): 1,526.57 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] setup: 1,768.75 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (clinit): 120.93 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (typeflow): 2,626.58 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (objects): 3,042.60 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (features): 70.71 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] analysis: 5,958.54 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] universe: 179.95 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (parse): 229.34 ms, 2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (inline): 432.89 ms, 2.64 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] (compile): 1,737.58 ms, 2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] compile: 2,715.36 ms, 2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] image: 633.62 ms, 2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] write: 201.14 ms, 2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122] [total]: 11,592.85 ms, 2.66 GB
Warning: Image '/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).
Created native image /Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT
@kamuela Start with hello world https://github.com/lread/clj-graal-docs
Ok, I'm now using this
$NATIVE_IMAGE \
-jar target/hello-world-0.1.0-SNAPSHOT-standalone.jar \
-H:Name=hello-world \
-H:+ReportExceptionStackTraces \
--initialize-at-build-time \
--verbose \
--no-fallback \
--no-server \
"-J-Xmx3g"
directly➜ graal-thing ./graal-thing
PING!
PONG!
Like a charm!I guess there's something I'm missing when trying to use @taylor's lein plugin
@kamuela you can try adding this to your project.clj with the plugin
:native-image {:name "hello-world"
:opts ["--initialize-at-build-time"
"--verbose"
"--no-fallback"
"--no-server"
"--report-unsupported-elements-at-runtime"]}
should work too--no-fallback
I understand, what does --no-server
do?
Or "-J-Xmx3g"
for that matter
I've tried plugins before, but I've had several problems that made me just use the vanilla thing via a script. Not worth the debugging time.
@kamuela You can read what this means by running native-image --help
or similar
i would echo @borkdude too and recommend to build the jar separately and compile afterwards
yeah or even just (compile 'foo.bar)
and then add classes
to your GraalVM native classpath
this is also documented in the hello world of clj-graal-docs, both approaches are
At the top of every namespace means
(ns graal-thing.core
(:gen-class))
(set! *warn-on-reflection* true)
?yes
Is that to do with the really long compile times?
you also want to enable direct linking. but all kinds of things can spike compile times, hard to say without context
afk
This worked, too. Thank you