E.3 Launching executable jars
The org.springframework.boot.loader.Launcher
class is a special bootstrap class that is used as an executable jars main entry point. It is the actual Main-Class
in your jar file and it’s used to setup an appropriate URLClassLoader
and ultimately call your main()
method.
There are 3 launcher subclasses (JarLauncher
, WarLauncher
and PropertiesLauncher
). Their purpose is to load resources (.class
files etc.) from nested jar files or war files in directories (as opposed to explicitly on the classpath). In the case of JarLauncher
and WarLauncher
the nested paths are fixed. JarLauncher
looks in BOOT-INF/lib/
and WarLauncher
looks in WEB-INF/lib/
and WEB-INF/lib-provided/
so you just add extra jars in those locations if you want more. The PropertiesLauncher
looks in BOOT-INF/lib/
in your application archive by default, but you can add additional locations by setting an environment variable LOADER_PATH
or loader.path
in application.properties
(comma-separated list of directories or archives).
E.3.1 Launcher manifest
You need to specify an appropriate Launcher
as the Main-Class
attribute of META-INF/MANIFEST.MF
. The actual class that you want to launch (i.e. the class that you wrote that contains a main
method) should be specified in the Start-Class
attribute.
For example, here is a typical MANIFEST.MF
for an executable jar file:
Main-Class: org.springframework.boot.loader.JarLauncher Start-Class: com.mycompany.project.MyApplication
For a war file, it would be:
Main-Class: org.springframework.boot.loader.WarLauncher Start-Class: com.mycompany.project.MyApplication
Note | |
---|---|
You do not need to specify Class-Path entries in your manifest file, the classpath will be deduced from the nested jars. |
E.3.2 Exploded archives
Certain PaaS implementations may choose to unpack archives before they run. For example, Cloud Foundry operates in this way. You can run an unpacked archive by simply starting the appropriate launcher:
$ unzip -q myapp.jar $ java org.springframework.boot.loader.JarLauncher