Problem using JavaFX Application class

Sander Mak sander.mak at luminis.eu
Thu Feb 25 19:24:07 UTC 2016


In general, I think it's interesting  that many frameworks want reflective access to what are essentially internal implementation classes. Spring comes to mind, you'd want to export interfaces but not Spring bean implementation classes, even though the framework needs access to instantiate them.
Indeed and I'm sure Mark will bring proposals around this to the JSR soon.

That's good to hear, looking forward to updates on this.


As has been discussed before on this list, ServiceLoader has a special super-power in this regard, and I sort of expected JavaFX Application handling to have that same superpower for instantiating the Application class.
There isn't any notion of "superpower" as such. Instead, think of it as a special type of access check where access is checked to the service type (the super type) rather than the implementation type.

I'm not sure I follow this. ServiceLoader lives in the java.base module, and my service implementation class lives in my application module (without being exported). How is it not a 'superpower' that ServiceLoader can reach into my application module's non-exported package to instantiate that class? Or maybe I should adjust my view and think of the module system as responsible for doing the instantiation by virtue of the 'provides .. with ..' clause in module-info. As you can probably tell I'm not burdened by any implementation knowledge of the modular service loading mechanism at this point...

One more follow-up question: when I remove the main() method that invokes launch (see here: https://bitbucket.org/sandermak/javafx-application/diff/src/applicationmodule/application/Main.java?diff2=fca74ffbc28d&at=without-main), the following error comes up (build 9-ea+106-jigsaw-nightly-h4498-20160221):

Error: Main method not found in class application.Main, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

I hope Kevin or David can answer this but assuming this is output from `java -m` then it will be because that doesn't locate FX entry point (unlike `java -jar`). This may be something that needs to be fixed.

It is indeed output from `java -m`, and can be reproduced by running `compilerun.sh` from the without-main branch of this Git repo: https://bitbucket.org/sandermak/javafx-application/src/fca74ffbc28d698b53fb38ed779971a41a5e371d/?at=without-main


Sander


More information about the jigsaw-dev mailing list