Skip to content

Use ThinLauncher as a dependency  #173

Open
@JamesPeters98

Description

@JamesPeters98

Is it possible to use a Spring Boot project using the Thin Launcher as a dependency on another project?

I.e It would be useful if the Maven plugin generated a class that can be called to load all the dependencies into the ClassLoader of the dependant project.

Currently this doesn't seem possible, I have tried using reflection to start the ThinJarWrapper but that results in the ThinJarLauncher not being able to find the Main class:

        try {
            var clazz = Class.forName("org.springframework.boot.loader.wrapper.ThinJarWrapper");
            var method = clazz.getMethod("main", String[].class);
            method.invoke(null, (Object) new String[]{});
        } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
18:27:54] [Server thread/WARN]: Caused by: java.lang.IllegalStateException: Cannot locate main class in jar:file:/C:/Users/James/Documents/GitHub/ChestsPlusPlus/Server/plugins/ChestsPlusPlus-2.5-Beta.jar!/
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.thin.ArchiveUtils.findMainClass(ArchiveUtils.java:98)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.thin.ThinJarLauncher.getMainClass(ThinJarLauncher.java:347)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.Launcher.launch(Launcher.java:57)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.thin.ThinJarLauncher.launch(ThinJarLauncher.java:195)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:141)
[18:27:54] [Server thread/WARN]: 	... 28 more
[18:27:54] [Server thread/WARN]: Caused by: java.lang.IllegalStateException: Unable to find a single main class from the following candidates [com.jamesdpeters.chestsplusplusdatabase.ChestsPlusPlusDatabaseApplication, com.jamesdpeters.minecraft.chests.lang.LangFileProperties, org.springframework.boot.loader.wrapper.ThinJarWrapper]
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.tools.MainClassFinder$SingleMainClassCallback.getMainClassName(MainClassFinder.java:432)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.tools.MainClassFinder$SingleMainClassCallback.access$100(MainClassFinder.java:403)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.tools.MainClassFinder.findSingleMainClass(MainClassFinder.java:198)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.tools.MainClassFinder.findSingleMainClass(MainClassFinder.java:180)
[18:27:54] [Server thread/WARN]: 	at org.springframework.boot.loader.thin.ArchiveUtils.findMainClass(ArchiveUtils.java:94)
[18:27:54] [Server thread/WARN]: 	... 32 more

The ideal situation would be to be able to call a class that would load everything into the classpath without actually launching the main method of the Spring Boot application - since that can now be handled by the dependant project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions