If you are running your application from a container, you can use an executable jar, but it is also often an advantage to explode it and run it in a different way. Certain PaaS implementations may also choose to unpack archives before they run. For example, Cloud Foundry operates this way. One way to run an unpacked archive is by starting the appropriate launcher, as follows:
$ jar -xf myapp.jar
$ java org.springframework.boot.loader.JarLauncher
This is actually slightly faster on startup (depending on the size of the jar) than running from an unexploded archive. At runtime you shouldn’t expect any differences.
Once you have unpacked the jar file, you can also get an extra boost to startup time by running the app with its "natural" main method instead of the JarLauncher
. For example:
$ jar -xf myapp.jar
$ java -cp BOOT-INF/classes:BOOT-INF/lib/* com.example.MyApplication
Note
|
Using the JarLauncher over the application’s main method has the added benefit of a predictable classpath order.
The jar contains a classpath.idx file which is used by the JarLauncher when constructing the classpath.
|
More efficient container images can also be created by creating separate layers for your dependencies and application classes and resources (which normally change more frequently).