mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Document CDS support
Closes gh-40061
This commit is contained in:
parent
a4b4a881cd
commit
4e62aae1a0
@ -6,30 +6,27 @@
|
|||||||
[[deployment.efficient.unpacking]]
|
[[deployment.efficient.unpacking]]
|
||||||
== Unpacking the Executable JAR
|
== Unpacking the Executable JAR
|
||||||
|
|
||||||
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.
|
If you are running your application, you can use an executable jar, but it is also often an advantage to extract it and run it in a different way.
|
||||||
Certain PaaS implementations may also choose to unpack archives before they run.
|
Certain PaaS implementations may also choose to extract archives before they run.
|
||||||
For example, Cloud Foundry operates this way.
|
For example, Cloud Foundry operates this way.
|
||||||
One way to run an unpacked archive is by starting the appropriate launcher, as follows:
|
|
||||||
|
With the help of the jarmode, you can extract the jar to different layouts.
|
||||||
|
The most efficient layout is a CDS (class data sharing) friendly layout.
|
||||||
|
This layout is used by default.
|
||||||
|
|
||||||
|
In this layout, the libraries are extracted to a `lib/` folder, and the application JAR
|
||||||
|
contains the application classes and a manifest which references the libraries in the `lib/` folder.
|
||||||
|
|
||||||
[source,shell]
|
[source,shell]
|
||||||
----
|
----
|
||||||
$ jar -xf myapp.jar
|
$ java -Djarmode=tools -jar my-app.jar extract
|
||||||
$ java org.springframework.boot.loader.launch.JarLauncher
|
$ java -jar my-app/my-app.jar
|
||||||
----
|
----
|
||||||
|
|
||||||
This is actually slightly faster on startup (depending on the size of the jar) than running from an unexploded archive.
|
This is actually faster on startup (depending on the size of the jar) than running from an unexploded archive.
|
||||||
After startup, you should not expect any differences.
|
After startup, you should not 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:
|
TIP: Run `java -Djarmode=tools -jar my-app.jar help extract` to see all possible options.
|
||||||
|
|
||||||
[source,shell]
|
|
||||||
----
|
|
||||||
$ 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.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user