apposed / jaunch

Launch Programs 𝙔𝙤𝙪𝙧 Way! 🍔
The Unlicense
6 stars 2 forks source link

JavaFX add-opens fiji.toml support #51

Open karlduderstadt opened 1 month ago

karlduderstadt commented 1 month ago

First of all, thank you for all your awesome work on jaunch! In my testing it works as expected/described!

I have several questions about JavaFX support as fiji migrates to jaunch and Java 11 and higher. I am not sure this will be the correct place for all of them, but I hope this is a good starting place.

The GUI for our collection of Fiji tools (Mars), uses JavaFX and depends on direct access to several JavaFX classes. Starting with Java 9, we now have the module system. I had to add the following lines to the fiji.toml for the Mars GUI to have the access needed to run:

'JAVA:9+|--add-opens=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED',
    'JAVA:9+|--add-opens=java.base/java.lang.reflect=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.base/com.sun.javafx.runtime=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.base/com.sun.javafx.binding=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.base/com.sun.javafx.event=ALL-UNNAMED',
    'JAVA:9+|--add-opens=javafx.graphics/com.sun.javafx.stage=ALL-UNNAMED'

Will it be possible to add these through update sites? Otherwise, could these be added to the fiji.toml?

When I launch fiji, with these lines added to the toml, I get the following warnings in the terminal:

WARNING: Unknown module: javafx.controls specified to --add-opens
WARNING: Unknown module: javafx.graphics specified to --add-opens
WARNING: Unknown module: javafx.base specified to --add-opens
WARNING: Unknown module: javafx.controls specified to --add-opens
WARNING: Unknown module: javafx.graphics specified to --add-opens
WARNING: Unknown module: javafx.base specified to --add-opens
WARNING: Unknown module: javafx.base specified to --add-opens
WARNING: Unknown module: javafx.controls specified to --add-opens
WARNING: Unknown module: javafx.graphics specified to --add-opens

I think I get these warning became now the JavaFX jars are no longer bundled with the JDK, but instead are now in the jars folder. I think the jars in the jars folder haven't yet been added to the class path during startup and perhaps this is why I receive these warnings.

Is there a way to prevent these warning from happening?

On my M2 Mac Studio machine, when compiling mars-fx in IntelliJ IDEA using the following pom, the following jars are added to the jars folder:

javafx-base-21-mac-aarch64.jar
javafx-base-21.jar
javafx-controls-21-mac-aarch64.jar
javafx-controls-21.jar
javafx-fxml-21-mac-aarch64.jar
javafx-fxml-21.jar
javafx-graphics-21-mac-aarch64.jar
javafx-graphics-21.jar
javafx-media-21-mac-aarch64.jar
javafx-media-21.jar
javafx-swing-21-mac-aarch64.jar
javafx-swing-21.jar
javafx-web-21-mac-aarch64.jar
javafx-web-21.jar
javafxsvg-1.3.0.jar

It seems the jars will depend on the java version as well as possibly the computer architecture. How should these jars be distributed? Can I somehow help with testing/evaluating what should be done? (maybe I should post this question elsewhere, but I am not really sure where)

ctrueden commented 1 month ago

@karlduderstadt Thank you very much for testing this!

Will it be possible to add these through update sites?

Yes, issue #38 tracks the need for this.

Is there a way to prevent these warning from happening?

Java now has the module path as well as the classpath. Maybe if you add those JavaFX JARs to the module path, it will work. Right now, the fiji.toml Jaunch configuration adds only the imagej-launcher JAR to the classpath—unless you pass the --full-classpath flag, or run in --python mode, in which case it puts all JARs in jars/*/*.jar and plugins/*.jar on the classpath. But in no case does Jaunch put anything on the module path right now.

Or, it may be that simply having them on the classpath at startup is sufficient to quelch the warnings. Do you see the warnings when you run in Python mode and/or with the --full-classpath flag? You can use the --dry-run flag to see exactly how Jaunch is launching Java under the hood.

It seems the jars will depend on the java version as well as possibly the computer architecture. How should these jars be distributed?

Platform-specific JARs go into a subfolder of jars. For mac-aarch64, it'll be jars/macosx-arm64. The Updater is smart enough to mark JAR files in the platform-specific folders as specific to the respective platform in the db.xml metadata, meaning that only Fiji installations running on the matching platform will download them.

karlduderstadt commented 2 weeks ago

Thanks for the prompt feedback. Sorry I was so slow to reply.

Yes, issue #38 tracks the need for this.

Wonderful! I didn't realize there was already an issue.

Or, it may be that simply having them on the classpath at startup is sufficient to quelch the warnings. Do you see the warnings when you run in Python mode and/or with the --full-classpath flag?

I tried using --full-classpath in different combinations with or without python. In all cases, I am still getting the warnings. I also added the --dry-run flag and I can see all the jars are added. However, I still get the warnings. This surprises me. I will keep testing.

Platform-specific JARs go into a subfolder of jars. For mac-aarch64, it'll be jars/macosx-arm64. The Updater is smart enough to mark JAR files in the platform-specific folders as specific to the respective platform in the db.xml metadata, meaning that only Fiji installations running on the matching platform will download them.

This sounds like a great solution. I didn't know about this.

Sounds like all the important details are being worked on. The warning are a minor issue and not urgent, but I guess in the long run it would be nice if there were no warnings. I will keep exploring.