Re: Spring Boot Choose Main Class #spring #springboot #java

Ben Hale <bhale@...>

This is more a question for the Spring Boot team, but here's how Spring Boot applications in Cloud Foundry work.

When a Spring Boot application is created, your application is put into `/BOOT-INF` and a "wrapper" application is put into the root of the JAR. The `Main-Class` manifest entry is pointed at one of the Boot launchers (`JarLauncher`, `WarLauncher`, or `PropertiesLauncher`). Then when your application is started via `java -jar app.jar`, that `*Launcher` bootstraps a classpath with everything in `BOOT-INF` and then invokes the value read from the manifest `Start-Class` entry. So the only user of `Start-Class` is Boot itself, not the JVM.

In Cloud Foundry we are presented with the exploded JAR file, which makes no difference to how the application is invoked. We create a classpath at the root of the application and invoke the `Main-Class` entry of the manifest (`java -cp . <Main-Class>`) bootstrapping the Boot `*Launcher` as if it had been executed with `java -jar`. At this time, Boot takes over and creates its own internal classloader and invokes `Start-Class` as it would normally do.

If you are having an issue where Boot is not invoking the entry in `Start-Class` then that's a question for the Boot team, not Cloud Foundry.

-Ben Hale
Cloud Foundry Java Lead

On Apr 17, 2019, at 07:22, Mrc0113 <marcd@...> wrote:

thanks Steve - at first I thought this would work, but it looks like Spring Boot is using "org.springframework.boot.loader.JarLauncher" as the main class so I don't want to override that. It looks like when run in an executable jar the JarLauncher looks at the Start-Class in the MANIFEST.MF file, but it doesn't seem to be respecting that in cf.
I sshed into the cf container and found that the MANIFEST looks correct (it has the main-class set to JarLauncher and start-class set to my class), but it also seems that during the cf push the executable jar was exploded. It seems that after being exploded the JarLauncher class is no longer respecting the "Start-Class" set in the Manifest. Any insight into that?

Join to automatically receive all group messages.