Skip to content

Support running different main class from fat jar #20404

@ttddyy

Description

@ttddyy

Our applications contain multiple main classes via dependent jar library.
(e.g.: a dependent jar contains simple tool app to run db upgrade.)

Currently, [Jar|War]Launcher reads Start-Class from manifest file and simply fails if it doesn't exist.
Since [Jar|War]Launcher is used for fat jar, java -jar method cannot run different main class when there are other main classes available in the jar(maybe nested jar).

Workaround is to use PropertiesLauncher with java -cp.

java -cp app.jar -Dloader.main=com.example.AnotherApplication  org.springframework.boot.loader.PropertiesLauncher

Similar to jarmode, it would be nice to allow [Jar|War]Launcher to take special system property to allow overriding start-class.

e.g.:

java -jar -Dstart-class=com.example.AnotherApplication app.jar

This way, user can just use java -jar instead of java -cp ... with PropertiesLauncher.
Since many users simply use java -jar, it is convenient and discoverable option than PeropertiesLauncher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions