Fork me on GitHub

hi, still playing with building a native image for javafx app written in clojure. idea is just to rewrite gluon’s HelloFX in clojure and get it built into a native image. getting somwhere: latest build for macos: unfortunately it fails with this when I try to run it:

fazekasbenedek@scatha:~/projects/tmp$ ./clj-hellofx
Hello, JAVA main, argc = 1, argv = 0x7ffee201a7f8
2021-02-24 16:54:49.741 clj-hellofx[34827:29435253] Starting Gluon VM...
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: Could not locate clojure/core/server__init.class, clojure/core/server.clj or clojure/core/server.cljc on classpath.
	at clojure.lang.RT.load(
	at clojure.lang.RT.load(
	at clojure.core$load$fn__6856.invoke(core.clj:6115)
	at clojure.core$load.invokeStatic(core.clj:6114)
	at clojure.core$load.doInvoke(core.clj:6098)
	at clojure.lang.RestFn.invoke(
	at clojure.core$load_one.invokeStatic(core.clj:5897)
	at clojure.core$load_one.invoke(core.clj:5892)
	at clojure.core$load_lib$fn__6796.invoke(core.clj:5937)
	at clojure.core$load_lib.invokeStatic(core.clj:5936)
	at clojure.core$load_lib.doInvoke(core.clj:5917)
	at clojure.lang.RestFn.applyTo(
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$load_libs.invokeStatic(core.clj:5974)
	at clojure.core$load_libs.doInvoke(core.clj:5958)
	at clojure.lang.RestFn.applyTo(
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$require.invokeStatic(core.clj:5996)
	at clojure.core$require.doInvoke(core.clj:5996)
	at clojure.lang.RestFn.invoke(
	at clojure.lang.Var.invoke(
	at clojure.lang.RT.doInit(
	at clojure.lang.RT.init(
	at clojure.lang.Util.loadWithClass(
	at thomasa.Main.<clinit>(Unknown Source)


@tvaughan reported a similar problem back in 2020 aug 20th here


(not with javafx tho) wonder if anybody seen similar and maybe has a pointer what to poke to fix it…


I tried many different approaches, and this didn't work until newer versions of depstar and graalvm were released. I currently use 2.0.171 and 21.0. Complete setup: Oh, and Clojure 1.10.2 too. For some reason I have to explicitly include Clojure 1.10.2 in deps.edn even though this is the only version I have installed


thanks i thought i was using those versions of clojure and graalvm (not using depstar), will dig around in kibit-runner, thanks for the link


i am lying i am using 1.10.3-rc1


@benedek This problem manifests itself when a project has dynamic requires that aren't executed during compilation. The namespace is then not available anymore after compilation. GraalVM works a bit like the Google Closure compiler, cutting away code it didn't come across during analysis.


You can probably work around this by requiring clojure.core.server during compilation already


For whatever reason this is necessary. I think it would even be better to get to the root of what is needing clojure.core.server since this namespace seems a bit unnecessary for a JavaFX project perhaps


> You can probably work around this by requiring clojure.core.server during compilation This did not work for me, fyi


I am trying now locally. I can successfully run the app with:

java -cp target/classes:$(clojure -Spath) thomasa.Main


The notes are missing the compiled classes on the classpath


But I can't find any details as how the native-image compilation is supposed to be kicked off with this gluon stuff


Trying now with mvn client:build


Ah I can reproduce the problem locally yes


It might be related to --initialize-at-build-time, this is generally what you need for Clojure projects


I see the pom.xml already has this for clojure, so it should work, hmm


thanks for looking at it @borkdude


Yeah, so normally you do --initialize-at-build-time and then making exceptions with --initialize-at-runtime=... for Clojure projects


Don't really know anything about JavaFX unfortunately


yeah that would be the main aim of this experiment to figure it out :)


but this error feels like related to the config you quoted above not really javafx... but guessing only...


Maybe you can bug the folks at Gluon about this a bit. I know Johan Vos is on the GraalVM slack as well, you can maybe poke him in the native-image channel


It would help converting your notes.txt into a shell script which you can actually execute


yup, good idea, thx


the notes file maybe a bit misleading even, the github workflow file is the real definition of the build: