Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to launch Spring boot application #156

Open
zeljkosh opened this issue Apr 9, 2019 · 4 comments
Open

Unable to launch Spring boot application #156

zeljkosh opened this issue Apr 9, 2019 · 4 comments

Comments

@zeljkosh
Copy link

zeljkosh commented Apr 9, 2019

I did try the launcher on several normal javafx applications and it works really nice, however when i did try to do it with spring boot it fails , giving me log file with just some "launcher" error and then i got stuck. I did however see that since version .18 spring boot is supported, so perhaps i am doing something wrong.

https://github.com/zeljkosh/demo
There is a link of my repo with just demo code, but you can check pom file if i am making any error.

Apr 09, 2019 12:10:52 PM fxlauncher.AbstractLauncher syncFiles INFO: Using cache dir C:\Users\ITsZeus\AppData\Local\Demo Apr 09, 2019 12:10:52 PM fxlauncher.AbstractLauncher createApplicationEnvironment INFO: Loading appClass com.example.demo.DemoApplication

that is above info from log file.

launcher it self throws two errors :

java.lang.NoClassDefFoundError: org/springframework/context/ConfigurableApplicationContext at com.example.demo.DemoApplication.start(DemoApplication.java:33) at fxlauncher.Launcher.startApplication(Launcher.java:242) at fxlauncher.Launcher.lambda$launchAppFromManifest$2(Launcher.java:194) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method) at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:204) at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511) at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107) at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:590) at javafx.stage.Stage.showAndWait(Stage.java:474) at javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:162) at javafx.scene.control.Dialog.showAndWait(Dialog.java:341) at fxlauncher.Launcher$1.lambda$reportError$2(Launcher.java:84) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.springframework.context.ConfigurableApplicationContext at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 24 more

I hope someone can help me, thank you. if you need anything else let me know

@zeljkosh
Copy link
Author

Well i had little chance to play again today, i tried to use headless launcher, and i did found this, however no luck.headless launcher would throw same mistake.
Now since 1.0.18 update perhaps it should work without it, but informations are quite limited on this subject and i had no luck making it work.
Any form of help would be appreciated!

@zeljkosh
Copy link
Author

Well, i think i found a bug, and it is bit weird one.
For the sake of clarity i will post just the parts of pom.xml that are important for this bug .

             <execution>
                          <id>embed-custom-ui-in-launcher</id>
                          <phase>package</phase>
                          <goals>
                              <goal>exec</goal>
                          </goals>
                          <configuration>
                              <executable>jar</executable>
                              <workingDirectory>${app.dir}</workingDirectory>
                              <arguments>
                                  <argument>uf</argument>
                                  <argument>fxlauncher.jar</argument>
                                  <argument>-C</argument>
                                  <argument>${project.basedir}/../demo/target/classes</argument>
                                  <argument>.</argument>
                              </arguments>
                          </configuration>
                      </execution>-->
                    


                    <execution>
                        <id>configure-headless-launcher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>jar</executable>
                            <workingDirectory>${app.dir}</workingDirectory>
                            <arguments>
                                <argument>uef</argument>
                                <argument>fxlauncher.HeadlessMainLauncher</argument>
                                <argument>fxlauncher.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>

Above there are 2 execution settings, one to setup custom UI , and the other that sets the headless launcher.

When i comment setting of the custom UI out the application works, but when i want to setup custom ui, the application fails :

Here is the stack trace when custom ui option is enabled :

Apr 13, 2019 8:05:11 PM fxlauncher.AbstractLauncher createApplicationEnvironment
INFO: Loading appClass com.example.demo.DemoApplication
Exception in Application init method
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at fxlauncher.HeadlessMainLauncher.launchApp(HeadlessMainLauncher.java:76)
        at fxlauncher.HeadlessMainLauncher.process(HeadlessMainLauncher.java:51)
        at fxlauncher.HeadlessMainLauncher.main(HeadlessMainLauncher.java:33)
Caused by: java.lang.RuntimeException: Exception in Application init method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:912)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/builder/SpringApplicationBuilder
        at com.example.demo.DemoApplication.bootstrapSpringApplicationContext(DemoApplication.java:57)
        at com.example.demo.DemoApplication.init(DemoApplication.java:28)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:841)
        ... 2 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.builder.SpringApplicationBuilder
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 5 more

I hope anyone else can test just to confirm this, i did try with two different spring boot projects (both were just basic hello world stuff) but its the same. if i include headless launcher settings and comment out custom UI one, it works, but if i dont comment out custom UI execution settings it crashes.
100% recurrence rate.

@wcrozeta
Copy link

@zeljkosh, an alternative is change the class Launcher.java to call HeadlessMainLauncher.main(args) when appClass ins't subclass of javafx.application.Application! Doing it I could load CustomUI and Spring Boot 2.0 together.

private static String[] args;
public static void main(String[] args) {
    	Launcher.args = args;
        launch(args);
}

@Override
        protected void createApplication(Class<Application> appClass) {
            runAndWait(() ->
            {
                try {
                    if (Application.class.isAssignableFrom(appClass)) {
                        app = appClass.newInstance();
                    } else {
                    	
                    	HeadlessMainLauncher.main(args);
                        //throw new IllegalArgumentException(String.format("Supplied appClass %s was not a subclass of javafx.application.Application!", appClass));
                    }
                } catch (Throwable t) {
                    reportError("Error creating app class", t);
                }
            });
        }

@FelipeAumannRS
Copy link

FelipeAumannRS commented Mar 17, 2022

@wcrozeta hope you see that
commenting on your previous response:

"app = appClass.newInstance();"
what app should be? Is it an instance of my class which extends Application (the same one which holds public static void main(String[] args) ?)
e.g: MyMainClass extends (ClassToInherit)
MyMainClass app = appClass.newInstance();

Also, my class isn't covering the method "createApplication(Class appClass)". Which class should I extend in order to override this method?
UPDATE: I should inherit Launcher from fxlauncher, but who should call for this method?

Also, I can't call Launcher.args (since args is not located in Launcher class from fxlauncher dependency)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants