Executing an Arbitrary Main Class from a Spring Boot JAR

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

A Spring Boot JAR comes with all an application needs to function, and the application can be started as simply as:

java -jar my-app.jar

This works because there is a well defined entry point that bootstraps the Spring Boot runtime. The application bytecode is maintained under a BOOT-INF directory inside the JAR. However, this interferes with an attempt to run an arbitrary main class as follows:

java -cp my-app.jar com.example.Main

If "com.example.Main" is present under BOOT-INFO, it can be executed as follows:

java -cp my-app.jar -Dloader.main=com.example.Main org.springframework.boot.loader.PropertiesLauncher arg0, arg1, ....