bailuk / java-gtk

GTK bindings for Java
MIT License
108 stars 8 forks source link

Question: could this be combined via graalvm in theory? #6

Closed rubyFeedback closed 1 year ago

rubyFeedback commented 2 years ago

Question: could this be combined via graalvm in theory?

i am asking because graalvm is pretty cool, and others have managed to get SWING applications to run.

My use case would be more like taking an existing python or ruby code base, commandline stuff, and add a simple GUI around it. I don't really want to write in C though (Java is ok but Swing is ugly, and JavaFX does not seem to be supported via Graalvm; also the graalvm team focuses not so much on GUIs)

JCWasmx86 commented 1 year ago

Yes, got it working: (Albeit quick and CLI-only, would be probably easier with Gradle/Maven)

git clone https://github.com/bailuk/java-gtk
cd java-gtk
make gen && make && make run
gradle assemble
java -agentlib:native-image-agent=config-output-dir=foo -cp ./examples/build/libs/examples.jar:./java-gtk/build/libs/java-gtk.jar:$HOME/.m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar examples.App
# Play around a bit with every button of the image, otherwise you get (non-critical) errors at runtime of the native image
native-image -cp ./examples/build/libs/examples.jar:./java-gtk/build/libs/java-gtk.jar:$HOME/.m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar examples.App -H:ConfigurationFileDirectories=foo

After around 90 seconds you get an executable called examples.app with around 22MB. It is not comfortable, especially the generation of the metadata for GraalVM, but it works