Sunday, September 22, 2019

Loading external jar for SpringBoot

In case one builds one Springboot app which requires jar to be provided on runtime, here's the recipe:

  1. Change "Main-Class" attribute in jar manifest, here's one example of configuration in gradle:
    bootJar {
        manifest {
            attributes(
                "Main-Class": "org.springframework.boot.loader.PropertiesLauncher"
            }
        }
  2. To run the app, add loader.path parameter pointing to the folder location of the jar
    java -Dloader.path=lib/ -jar application.jar
Tips:
  1.  Default "Main-Class" in Springboot jar
    "Main-Class": "org.springframework.boot.loader.PropertiesLauncher
  2. "Start-Class" attribute in the manifest points to the main class, the class annotated with SpringBootApplication

No comments: