JDK-8102035 : Change launcher to always call the main method for standalone JavaFX applications
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: application-lifecycle
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-03-01
  • Updated: 2017-03-21
  • Resolved: 2013-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Description
In JDK 7 / FX 2.x main() is not called for applications packaged up with the javafx packager. It is also not called for Web Start applications (or applets). With the added FX support in Java 8, the Java launcher now bypasses main() for FX applications even if they are run from class files or from a jar file not packaged by the javafxpackager.

Note that we made a deliberate decision to dicourage / deprecate the main() method. This JIRA proposes to revisit this decision.

Pros:
Applications that don't use the javafxpackager will expect main to be called and may be surprised when it isn't.

Cons:
This goes against the goal of unifying the application startup model, since the main method would be called for standalone apps, but not called for applets and web start apps.

If we decide to do this, it should be a fairly simple change in the launchApplicationWithArgs() method, which is called by the FX application helper. It could detect whether a main method is present. Is so, it would startup the toolkit and call the main() method. It would need to set a flag indicating that the toolkit was started in this fashion so the launchApplication() method (which would then be called by main) would not try to start it again. If no main method is present, it would call launchApplication() as it does now.
Comments
[deleted comment meant for another, related bug
28-10-2014

Unit Tests: launchertest/MainLauncherTest
20-05-2013

This will be available in b91
18-05-2013

No, the SE launcher should not need to be changed to do this, the last round of changes was done under the concept of "if it's an FX app, pass complete control off to the FX launcher". This should actually be a fairly trivial change.
02-03-2013

It seems there is consensus that this RFE should be done, and that we should always call main() for standalone FX applications if main is present. The change to the Java 8 launcher was done through the JDK CCC process: http://ccc.us.oracle.com/8004547 However, changing the FX launcher to always call main can be done entirely on the FX side, so I don't think a new JDK CCC is needed. This seems like the sort of change that is best done sooner rather than later. Given that we also want this change to affect apps packaged with javafxpackager, I think it will be helpful to change the packager-inserted Main class so we can test this with JDK7 as well (many of us still run FX 8 internally with JDK7), although this isn't as crucial.
02-03-2013

I agree with Rich, if there is a main method then it should be called as it is today. If there is no main method then the Application should run as expected via init() and start(). We should also do the same for Packager so we are consistent.
02-03-2013

It seems like, if a main() method is specified, we need to keep calling it with the same semantics we do today. If there is no main method, then we just launch the app. It seems like any breaking change should have been brought through CCC / API review in any case.
01-03-2013

If we are going to do this, we need to do it for FX 8 since the behavior change of not calling main for non-javafx-packaged apps has not yet been released (it's just in early access builds of 8). For what it's worth, the change to not call main has already caused some SQE tests to fail and need to be redone. See RT-27808, which I closed as "Not an Issue" since the change was intentional. Seems like there is good reason to revisit this.
01-03-2013

Incidentally it may also break jtreg which also looks for a main
01-03-2013

Note that not calling main() is a breaking change on the desktop. It breaks both application code and IDE's because they use main() to determine whether a class can be launched. We need to continue to call main().
01-03-2013