Fork me on GitHub
#cljfx
<
2020-09-12
>
Grigory Shepelev09:09:23

@vlaaad I had to add {:aot :all :injections [(javafx.application.Platform/exit)]} to my uberjar properties in project. But now I have another problem. For some reason the process is not terminating after closing the window. I still can see it in my htop...

vlaaad10:09:33

Javafx runs a non-daemon thread that prevents jvm from terminating

vlaaad10:09:10

You can set implicit exit to true to make it terminate the vm on closing the last window

vlaaad10:09:34

This for not make sense for repl, but useful for -main

Grigory Shepelev10:09:37

Tnhx. I will rty right now

Grigory Shepelev10:09:51

It's not helping. Should I add something to :on-close-request of stage ?

vlaaad11:09:40

Can you share your source so I can have a look?

vlaaad11:09:30

It's hard to know why implicit exit is not enough

Grigory Shepelev11:09:28

I can share access to the source code in GitLab

Grigory Shepelev11:09:33

I gave an access with <mailto:[email protected]|[email protected]> You should see an invite. All the code in pdf-only-export branch, in gui.clj and app.clj file

vlaaad11:09:42

Thanks! I'll try to have a look today

vlaaad11:09:50

I can't see the code though...

Grigory Shepelev12:09:03

Do you mean you can't see code on gitlab? I have guest access Sorry for late reply... For some reason I can't see notifications on phone

vlaaad13:09:32

Yes, I can open the repo, but I can't see the code

vlaaad13:09:05

Maybe guest access isn't enough?

vlaaad13:09:39

Or you can add some permission to guest accounts... I don't know gitlab well enough :)

Grigory Shepelev08:09:27

ok. sorry for a late reply again. I just gave a developer access.

vlaaad11:09:54

@UKG0SELQY I managed to aot-compile your example so it exits the jvm when the windows is closed, there were a couple things missing:

vlaaad11:09:33

hit send too early 🙂

vlaaad11:09:39

1. in the main ns I added this to ns form:

(:import [javafx.application Platform])
  (:gen-class)
2. in the -main fn in main ns I added (Platform/setImplicitExit true) 3. in project.clj, I added this to :uberjar profile:
:jvm-opts ["-Dcljfx.skip-javafx-initialization=true"]
4. I removed ^:skip-aot from project.clj 5. I bumped cljfx version to latest (1.7.9). It is very important for aot because skipping cljfx initialization was added in a later version than what you had specified 🙂

vlaaad11:09:43

cljfx.skip-javafx-initialization was added in 1.7.0 and you had 1.6.6

Grigory Shepelev11:09:24

I will try right now

Grigory Shepelev11:09:49

Thnx. Now it works as expected on close. I had :jvm-opts outside of :uberjar... May be that's also the problem

Grigory Shepelev11:09:03

Best lib maintainer in my life.

vlaaad12:09:23

Haha thanks

vlaaad12:09:36

Become my sponsor on GitHub :P

vlaaad12:09:45

Or make your employer do that!

Grigory Shepelev12:09:35

I'm unemployed/ I promise that I'll send one-time 20$ from my first salary.

vlaaad14:09:58

Haha, no pressure :) you are welcome!

Grigory Shepelev14:09:21

I have one more question. It might be out of your competence. When I pack it with uberjar and run on Windows I see the exception: "A java exception has occured". And that's all basically. Nothing more. Is it connected to cljfx?

vlaaad14:09:57

Try running it from the command line to see the exception

vlaaad14:09:40

If you want to distribute your app, I would also recommend to look at jpackage

vlaaad14:09:07

This example app doesn't use leiningen, but the jpackage part of the packaging is independent from the build tool, i.e. it works on uberjar

Grigory Shepelev15:09:01

when i run it on windows cli I have:

"Graphics Device initialization failed for : d3d, sw" Problem
Exception. It seems to be connected to this (https://stackoverflow.com/questions/55561986/how-to-solve-the-graphics-device-initialization-failed-for-d3d-sw-problem) question.

Grigory Shepelev15:09:28

I'm a total newbie in java-related-devops.

vlaaad15:09:05

how do you run the assembled jar?

Grigory Shepelev15:09:32

java -jar jarname.jar

vlaaad15:09:59

do you use the -standalone.jar version built by leiningen?

Grigory Shepelev15:09:50

That's the strange. Thing. It feels like it's not standalone.

vlaaad15:09:08

exactly what I thought

vlaaad15:09:33

do you assemble the standalone jar on the same OS as the OS you try to run on?

vlaaad15:09:49

e.g. do you build the windows jar on windows?

Grigory Shepelev15:09:56

I build on ubuntu.

vlaaad15:09:13

that’s the problem 🙂

Grigory Shepelev15:09:18

Won't that work on Win? I thought that's the goal of java....

vlaaad15:09:55

even though jar is cross-platform, this cross-platformness is only about the class files

vlaaad15:09:19

in addition to class files, jars might contain platform-specific libraries

vlaaad15:09:28

javafx has platform-specific libraries

vlaaad15:09:15

it also configured it’s maven dependencies in a way that automatically selects the jars for the OS we resolve maven deps for

Grigory Shepelev15:09:43

How can I set that up?

Grigory Shepelev15:09:38

Is that possible

vlaaad15:09:12

there are 2 ways around: 1. make sure you build jars for different platforms on different platforms. Example hacker news app I posted earlier has example of github actions that do it. Perhaps gitlab has similar infrastructure you can use? 2. force maven to include dependencies for all platforms. this means you will have a really fat jar that has platform-specific libraries for every platform. You do this by specifying ALL javafx classifiers as dependencies

Grigory Shepelev15:09:23

sorry for late reply

Grigory Shepelev16:09:16

So you build them with 3rd services (github can build platform-specific, for windows)?

vlaaad16:09:13

Yeah, GitHub has mac/windows/linux runners

Grigory Shepelev16:09:09

Cool. I'm a retrograde

Grigory Shepelev16:09:13

I can see that's kinda complicated stuff with a lot of yaml... Are you using CircleCI? Could you please share a piece of that code? So I

Grigory Shepelev16:09:25

have a little representation at least.

vlaaad16:09:58

That's GitHub Actions, their built-in CI

Grigory Shepelev16:09:54

Do you still have some config-yaml?

Grigory Shepelev17:09:08

Oh.thnx. I didn't knew that's the workflow dir on that

vlaaad17:09:28

No problem :)