[cf-dev] Spring Boot Choose Main Class #spring #springboot #java

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[cf-dev] Spring Boot Choose Main Class #spring #springboot #java

marcd
Hi, 

I have a Spring Boot project which has multiple main classes (Yes - I know not best practices, but I'm not able to easily change it). The project is being built by maven. 
Locally I was able to specify a "start-class" on the spring-boot-maven-plugin and that works to define which main I want to run, however when I push the app to PCF that doesn't seem to work. 
It looks like my app is using the java buildpack... Is there someway to specify the main class that I want to run in PCF?  Maybe by settings an environment variable or as part of the cf push command? 

thanks! 
_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#8575) | [hidden email] | [hidden email] | Mute This Topic | New Topic
Mute #spring | Mute #springboot | Mute #java
Your Subscription | [hidden email] | Unsubscribe [[hidden email]]

_._,_._,_
Reply | Threaded
Open this post in threaded view
|

Re: [cf-dev] Spring Boot Choose Main Class #spring #springboot #java

Steve Taylor

Regards,
--Steve

On Tue, Apr 16, 2019 at 1:32 PM <[hidden email]> wrote:
Hi, 

I have a Spring Boot project which has multiple main classes (Yes - I know not best practices, but I'm not able to easily change it). The project is being built by maven. 
Locally I was able to specify a "start-class" on the spring-boot-maven-plugin and that works to define which main I want to run, however when I push the app to PCF that doesn't seem to work. 
It looks like my app is using the java buildpack... Is there someway to specify the main class that I want to run in PCF?  Maybe by settings an environment variable or as part of the cf push command? 

thanks! 

_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#8576) | [hidden email] | [hidden email] | Mute This Topic | New Topic
Mute #spring | Mute #java | Mute #springboot
Your Subscription | [hidden email] | Unsubscribe [[hidden email]]

_._,_._,_
Reply | Threaded
Open this post in threaded view
|

Re: [cf-dev] Spring Boot Choose Main Class #spring #springboot #java

marcd
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? 
_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#8578) | [hidden email] | [hidden email] | Mute This Topic | New Topic
Mute #spring | Mute #java | Mute #springboot
Your Subscription | [hidden email] | Unsubscribe [[hidden email]]

_._,_._,_
Reply | Threaded
Open this post in threaded view
|

Re: [cf-dev] Spring Boot Choose Main Class #spring #springboot #java

Ben Hale
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 <[hidden email]> 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?
>


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#8579): https://lists.cloudfoundry.org/g/cf-dev/message/8579
Mute This Topic: https://lists.cloudfoundry.org/mt/31204999/474226
Mute #spring: https://lists.cloudfoundry.org/mk?hashtag=spring&subid=920759
Mute #java: https://lists.cloudfoundry.org/mk?hashtag=java&subid=920759
Mute #springboot: https://lists.cloudfoundry.org/mk?hashtag=springboot&subid=920759
Group Owner: [hidden email]
Unsubscribe: https://lists.cloudfoundry.org/g/cf-dev/leave/920759/1741049355/xyzzy  [[hidden email]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply | Threaded
Open this post in threaded view
|

Re: [cf-dev] Spring Boot Choose Main Class #spring #springboot #java

marcd
Ben, 

This definitely helps me understand what's going on - thanks for the detailed explanation. I'll continue to look into it...I started on the Cloud Foundry list because it was working fine when run outside of cloud foundry; it's only when I pushed it to cf that this seems to happen. 

-Marc
_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#8582) | [hidden email] | [hidden email] | Mute This Topic | New Topic
Mute #spring | Mute #java | Mute #springboot
Your Subscription | [hidden email] | Unsubscribe [[hidden email]]

_._,_._,_