sialcasa / mvvmFX

an Application Framework for implementing the MVVM Pattern with JavaFX
Apache License 2.0
484 stars 105 forks source link

HostServicesFactory - ClassNotFoundException #607

Closed clogs1959 closed 4 years ago

clogs1959 commented 4 years ago

I am trying your project for using MvvmFX together with Spring Boot. During startup of the code I am getting an exception:

java.lang.ClassNotFoundException: com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at com.sun.javafx.application.HostServicesDelegate.lambda$getInstance$0(HostServicesDelegate.java:52) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.HostServicesDelegate.getInstance(HostServicesDelegate.java:45) at javafx.application.HostServices.(HostServices.java:52) at javafx.application.Application.getHostServices(Application.java:334) at de.saxsys.mvvmfx.spring.MvvmfxSpringApplication.hostServices(MvvmfxSpringApplication.java:34)

I am using Java Zulu (8u232) together with OpenJFX. The application still works, it just throws this exception. Should you really be depending on those good old classes from the Sun corporation?

manuel-mauky commented 4 years ago

Hi, this is likely not a bug in mvvmFX but in the JDK you are using. In https://github.com/sialcasa/mvvmFX/blob/develop/mvvmfx-spring-boot/src/main/java/de/saxsys/mvvmfx/spring/MvvmfxSpringApplication.java#L7 we are importing javafx.application.HostServices which is not from the sun package. We are using the standard JavaFX method Application.getHostServices(). The exception comes from internals of this method.

I have seen this exception also in the Amazon Corretto JDK but I'm not sure what to do about this exception. To verify this you could try a pure JavaFX application without mvvmFX and invoke the getHostServices() method. I assume that this excepion will also be thrown.

clogs1959 commented 4 years ago

I am not sure why you call the method in the first place. There are no comments in the source as to its purpose. 'Normal' JavaFX with Spring Boot doesn't exhibit this behaviour and works without exceptions. I guess you have included the call to the method for some specific reason. I will just ignore the exception, it does not seem to affect the running of the application.

manuel-mauky commented 4 years ago

The HostServices of JavaFX provide some special features, see https://docs.oracle.com/javase/8/javafx/api/javafx/application/HostServices.html For example I've used it in some applications to open a URL in the system browser.

In our dependency-injection sub-modules allow users to inject an instance of this HostService in their ViewModels to use this functionality. This is the reason why we call the getHostService method in our code: to make it accessible for dependency injection.

If you don't use HostServices it's fine to ignore this exception.