Create PeerMonitor class with Java FX
Its been mentioned a while ago to create a java fx version of the peer monitor class. Here is a first draft of the peer montior class using JavaFX. I noticed a few things when I created this class with JavaFX.
-
The
PeerMonitorFxfails to start up and gives an error that says> JavaFX runtime components are missing, and are required to run this application
I found that, when we have a main inside the class where we extend the JavaFX
Applicationclass we get the error above because of how theFXLauncherworks and the pre-checks for JavaFX components that happens when the main launcher sees that the application is a javafx application. See here. Looks like this has been the case since JavaFx was seperated out of the Java runtime.
-
I checked our
wallettemplatemodule which has javafx as well. When I run the main in there, I get the same error> JavaFX runtime components are missing, and are required to run this application -
One work around I did for the
PeerMonitorFxclass in this PR was to create a second class with a mainPeerMonitorMainwhich tricks the LauncherHelper into not realising the app is an instance of a JavaFX Application. (not an ideal solution) -
We might want to use modules i.e module-info.java to explicitly specify the JavaFx components required. ONly problem with modules is that when you have interdependent modules/packages like we have a bitcoinj, you might have to add a module-info file for every bitcoinj child module. Alternatively, a developer has to really know what he is doing to and always makes sure he has vm arguments like
--module-path /path/to/javafx-sdk-14/lib --add-modules javafx.controls,javafx.fxml
in IDE or cmd before running bitcoinj FX applications.
I have updated the size of the scene.
@msgilligan any thoughts on the comments above
The
PeerMonitorFxfails to start up and gives an error that says> JavaFX runtime components are missing, and are required to run this applicationI checked our
wallettemplatemodule which has javafx as well. When I run the main in there, I get the same error> JavaFX runtime components are missing, and are required to run this application
Take a look at the latest version of the wallettemplate app. It is now a modular app and can be linked with jlink so does not need a separate "main" class.
- We might want to use modules i.e org.beryx.jlink to explicitly specify the JavaFx components required. ONly problem with modules is...
I think before this PR is merged, we should move it to it's own bitcoinj submodule so we can add the application and org.beryx.jlink plugins, a module-info.java, etc.
Note that PeerMonitorFX.java can also be made into a JBang application and JBang will make it modular automatically. Adding the following lines to the top of the file makes it runnable as a JBang script:
//JAVA 17+
//DEPS org.openjfx:javafx-controls:21:${os.detected.jfxname}
//DEPS org.openjfx:javafx-graphics:21:${os.detected.jfxname}
//DEPS org.bitcoinj:bitcoinj-core:0.17
//DEPS org.slf4j:slf4j-jdk14:2.0.17
@ItoroD See PR #3832 for changes I made to move this to its own module and some other minor improvements.
Let's see what @schildbach says about creating a new module for it and if he agrees, you can update this PR with some of the work from #3832.