Skip to content

Improve exploded structure experience for efficient deployments #38276

Closed

Description

@snicoll

The reference guide has a section on unpacking the executable jar to get extra boost. It also has an additional hint for bypassing the bootlader with the impact on losing classpath ordering.

Our work on AppCDS (see spring-projects/spring-framework#31497) has shown that a predicable classpath has an impact on how effective the cache is going to be. Investigating a bit more, it looks doable to provide the above as a first class concept.

Here is a proposal that is hacking layertools with an additional extract2(sic) command: https://github.com/snicoll/spring-boot/tree/gh-38276

Ignoring the fact that this does use layertools for convenience, you can execute the following on any repackaged archive:

java -Djarmode=layertools -jar target/my-app-1.0.0-SNAPSHOT.jar extract2 --destination target/app

This creates a directory with the following structure:

target/app/
├── application
│   └── my-app-1.0.0-SNAPSHOT.jar
├── dependencies
│   ├── ...
│   ├── spring-context-6.1.0-RC2.jar
│   ├── spring-context-support-6.1.0-RC2.jar
│   ├── ...
└── run-app.jar

You can then run the app as follows (assuming you're in the same directory as the previous command):

java -jar target/app/run-app.jar

The run-app.jar has the following characteristics:

  • It starts the application class directly (no bootlader used)
  • The manifest defines a classpath with the same order as classpath.idx, with application/my-app-1.0.0-SNAPSHOT.jar being in front

my-app-1.0.0-SNAPSHOT.jar has some manifest entries of the original jar so that package.getImplementationVersion() continues to work.

The work on this prototype has led to a number of questions:

  • Layertools provide a Command infrastructure and several utilities related to extracting/copying that are not specific to layers. If we want to go the same route with a different jar mode, a significant number of classes should be copied/reimplemented. Perhaps a single jar with a public API and sub-packages for layertools and this new mode could be an option?
  • This work could potentially apply to layers themselves. Rather than having dependencies/BOOT-INF/lib and a layer for the bootloader, we could use the same exact structure. Or perhaps the structure above could become a layer configuration (where all libs go to dependencies).
  • It's hard for run-app.jar to have sensible File attributes. The command tries to respect the file attributes of files it extracts from the repackaged archive, but run-jar.jar is created on the spot.

We have confirmed that with the prototype, AppCDS is effective (close to 95% classes loaded from the cache).

Activity

  1. added
    status: waiting-for-triageAn issue that has not yet been triaged. Contributions will not be accepted.
    on Nov 9, 2023
  2. sergmain commented on Nov 15, 2023

    @sergmain

    About performance - In my project a data exchange between agents conducted via zip files. In one case I had 1k+ zips inside other zip and preparing data for agent by unziping all archives had taken minutes.
    After switching to com.google.jimfs the time of preparing reduced to hundreds milliseconds.
    So spending additional memory you can achieve almost zero time for unpacking without making any changes in structure.of archive.
    You can see a general concept here
    https://github.com/sergmain/metaheuristic/blob/master/apps/commons/src/test/java/ai/metaheuristic/commons/utils/ZipUtilsTest.java

    pom dependency

    <dependency>
        <groupId>com.google.jimfs</groupId>
        <artifactId>jimfs</artifactId>
        <version>1.2</version>
    </dependency>

    repo is here - https://github.com/google/jimfs

  3. snicoll commented on Nov 16, 2023

    @snicoll
    MemberAuthor

    @bclozel and I had a bit of brainstorming on this one and he raised a use case that could become problematic. The solution above ignores the Spring Boot launcher on purpose to make the startup as straightforward as possible. However, it currently does not allow to augment the classpath, which is something that can be problematic. I don't know if this is something we need to take into consideration, but the POC could be adapted accordingly.

  4. snicoll commented on Jan 5, 2024

    @snicoll
    MemberAuthor

    The PoC has been updated to provide the ability to include additional libraries. This is typically used by buildpacks, for instance:

    $ java -Djarmode=layertools -jar my-app.jar extract2 --destination target/app --additional-jars jar1.jar,jar2.jar
    

    This copies jar1.jar and jar2.jar available in the current directory to target/app/ext. The two jars are added at the end of the classpath in the manifest of run-app.jar.

    One decision could help move the POC into something that can be reviewed. If the above is working for buildpacks, perhaps this could become the default mode of operation for layer tools as well. In other words, merging extract and extract2.

    The structure above reuse the concept of "layers" to nicely separate concerns, except it does not expand the structure of the far jar (i.e. dependencies has libraries directly nested rather than BOOT-INF/lib). One could argue it is completely unnecessary and a simple lib directory with all jars (including the generated jar for the application) could be enough.

    Merging the two means we need to bring back the launcher, perhaps as an opt-in?

    Keeping things separate would be less disturbing. However, the argument that buildpacks would work with the new mechanism, and has to for optimal CDS performance, means two mode of operations that might not be desirable. There are also a lot of infrastructure in jarmode that would either need to be duplicated or abstracted.

    I am happy to improve the proposal based on what the team decides.

  5. wilkinsona commented on Jan 30, 2024

    @wilkinsona
    Member

    I spent some time looking at this last week and we discussed it a bit yesterday. The high-level conclusion was that we need to combine support for layers and CDS in a single command. This is necessary as the former needs to know about the latter so that the runner jar can go in the most frequently changing layer.

    At the moment, I'm imagining a single command with two options – one for CDS and one for layers – that can each be used individually and that can also be used together. There's quite a lot to figure out in terms of how we get from where we are now to where we want to be in a non-breaking manner. We hope that we might be able to look at this in March but there are other, higher priority items that require our attention in the 3.3.0-M2 timeframe.

  6. snicoll commented on Jan 31, 2024

    @snicoll
    MemberAuthor

    I spent some time looking at this last week and we discussed it a bit yesterday. The high-level conclusion was that we need to combine support for layers and CDS in a single command.

    Yes. I guess I should have dumped my thoughts somewhere as I reached the same conclusion. Considering the buildpacks use case, I see it as a continuation of what we've started when we introduce layertools back then. Buildpacks still need all the features that we've built so far, but with a mode of operation that allows to further tune the application before final packaging.

    Given the classpath cannot be extended further, a mode of operation could be that run-app.jar is created as part of repackaging the archive, so that its timestamp matches, rather than creating it on the fly when we extract the archive.

    Then, we need to review layers.xsd. So far, extract has taken the route of including all artifacts that are present in the archive, but this is no longer the case. Instead, there are libraries, application classes and resources, and a "loader". The loader can either be the Spring Boot loader or this new run-app.jar mode of operation. It's interesting to see that layers.xsd list the resources to include in a layer, not where they end up: the current mode extracts the resource as is in a directory that matches the layer name. This gives us the flexibility to know in advance how many layers there are, how many directories we need, and how to structure run-app.jar upfront.

    With buildpacks being updated upfront to support the new infrastructure, we could imagine a mode of operation where the build plugins introduce a flag that defaults to this run-app.jar mode rather than the classic mode we had so far. This would obviously force those who are crafting layered docker images to manually set a property when upgrading.

    There are a ton of things that I overlooked, but I am happy to dig further based on the team's guidance when it gets to this. Thanks!

  7. wilkinsona commented on Jan 31, 2024

    @wilkinsona
    Member

    Given the classpath cannot be extended further, a mode of operation could be that run-app.jar is created as part of repackaging the archive, so that its timestamp matches, rather than creating it on the fly when we extract the archive.

    We'd like to maintain the current model where the archive produced by the build plugins is the single source of truth. It can then be run as-is using java -jar or it can be further processed to produce a deployment-specific arrangement as it is today. We don't want the build plugins to produce the runner jar (and presumably the directory of dependencies along side it) directly as our feeling is that it will create too much confusion and introduce too much overlap with things like Gradle's application plugin and Maven's assembly plugin.

  8. added and removed
    status: waiting-for-triageAn issue that has not yet been triaged. Contributions will not be accepted.
    on Feb 1, 2024
  9. added this to the 3.x milestone on Feb 1, 2024
  10. removed
    for: team-meetingAn issue we'd like to discuss as a team to make progress
    on Feb 22, 2024
  11. modified the milestones: 3.x, 3.3.0-M3 on Mar 7, 2024
  12. 11 remaining items

  13. mhalbritter commented on Mar 12, 2024

    @mhalbritter
    Contributor

    After a bit of discussion we want to change the names of the produced artifacts a bit.

    The plan is:

    If you don't specify --destination, it will default to a directory named after the input JAR instead of the current working directory. Additionally, the runner.jar will be named like the input JAR.

    So given this:

    java -Djarmode=tools -jar app-0.0.1-SNAPSHOT.jar extract
    

    you'll get ./app-0.0.1-SNAPSHOT/app-0.0.1-SNAPSHOT.jar (which can be executed with java -jar) and the ./app-0.0.1-SNAPSHOT/libs/ directory.

    If you specify a directory with --destination, it will create the "runner" with the name like the input jar.

    So given this:

    java -Djarmode=tools -jar app-0.0.1-SNAPSHOT.jar extract --destination output
    

    you'll get ./output/app-0.0.1-SNAPSHOT.jar (which can be executed with java -jar) and the ./output/libs/ directory.

  14. added a commit that references this issue on Mar 12, 2024
  15. anthonydahanne commented on Mar 12, 2024

    @anthonydahanne
    Contributor

    and the ./app-0.0.1-SNAPSHOT.jar/libs/ directory

    You meant:

    and the ./app-0.0.1-SNAPSHOT/libs/ directory

    Right?
    Otherwise, changes dully noted. Thanks!

  16. mhalbritter commented on Mar 12, 2024

    @mhalbritter
    Contributor

    Yeah, you're right, that's a typo. I've edited the original post.

  17. wyhasany commented on May 13, 2024

    @wyhasany

    Hello, I'm strugging with preparing multi stage dockerfile. It works fine when I don't use layers:

    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.3-10-cds AS builder
    WORKDIR application
    COPY build/libs/*.jar app.jar
    RUN java -Djarmode=tools -jar app.jar extract --layers --destination out --application-filename app.jar
    RUN cp -R ./out/dependencies/* ./
    #When no loader and snapshot dependencies
    #RUN cp -R ./out/spring-boot-loader/* ./
    #RUN cp -R ./out/snapshot-dependencies/* ./
    RUN cp -R ./out/application/* ./
    RUN rm -rf ./out
    RUN java -Xshare:dump #-XX:+UseZGC
    RUN java \
        -Dspring.context.exit=onRefresh \
        -XX:ArchiveClassesAtExit=/application/app-cds.jsa \
        -Xshare:on \
        -jar app.jar
    
    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.3-10-cds
    WORKDIR application
    COPY --from=builder /usr/lib/jvm/jre/lib/server/classes.jsa /usr/lib/jvm/jre/lib/server/classes.jsa
    COPY --from=builder application .
    ENTRYPOINT ["java", "-XX:SharedArchiveFile=app-cds.jsa", "-Xshare:on", "-jar", "app.jar"]

    However if I would like to pass layers separately:

    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.1-cds AS builder
    WORKDIR application
    COPY build/libs/*.jar app.jar
    RUN java -Djarmode=tools -jar app.jar extract --layers --destination out --application-filename app.jar
    RUN cp -R ./out/dependencies/* ./
    #When no loader and snapshot dependencies
    #RUN cp -R ./out/spring-boot-loader/* ./
    #RUN cp -R ./out/snapshot-dependencies/* ./
    RUN cp -R ./out/application/* ./
    RUN rm -rf ./out
    RUN java -Xshare:dump #-XX:+UseZGC
    RUN java \
        -Dspring.context.exit=onRefresh \
        -XX:ArchiveClassesAtExit=/application/app-cds.jsa \
        -Xshare:on \
        -jar app.jar
    
    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.1-cds
    WORKDIR application
    COPY --from=builder /usr/lib/jvm/jre/lib/server/classes.jsa /usr/lib/jvm/jre/lib/server/classes.jsa
    COPY --from=builder application/lib ./lib                            
    COPY --from=builder application/app.jar ./app.jar                    
    COPY --from=builder application/app-cds.jsa /application/app-cds.jsa 
    ENTRYPOINT ["java", "-XX:SharedArchiveFile=app-cds.jsa", "-Xshare:on", "-jar", "app.jar"]

    I can see following error:

    [0.049s][warning][cds] A jar file is not the one used while building the shared archive file: lib/spring-webmvc-6.1.6.jar
    2024-05-13T12:51:53.072884000Z [0.049s][warning][cds] A jar file is not the one used while building the shared archive file: lib/spring-webmvc-6.1.6.jar
    2024-05-13T12:51:53.072885625Z [0.049s][warning][cds] lib/spring-webmvc-6.1.6.jar timestamp has changed.
    2024-05-13T12:51:53.073443041Z [0.050s][warning][cds,dynamic] Unable to use shared archive. The top archive failed to load: app-cds.jsa
    2024-05-13T12:51:53.073568750Z [0.050s][error  ][cds        ] An error has occurred while processing the shared archive file.
    2024-05-13T12:51:53.073572458Z [0.050s][error  ][cds        ] Unable to map shared spaces
    2024-05-13T12:51:53.073573500Z Error occurred during initialization of VM
    2024-05-13T12:51:53.073574375Z Unable to use shared archive.
    

    it seems that coping changes timestamps, can I avoid it somehow? The very same happens with Liberica JVM 21.0.3-10-cds

  18. wilkinsona commented on May 13, 2024

    @wilkinsona
    Member

    @wyhasany please see moby/moby#17175. I don't think there's anything we can do about it in Spring Boot, unfortunately.

  19. wyhasany commented on May 13, 2024

    @wyhasany

    @wilkinsona I think it is worth mentioning in docs, because using layered images could be confusing for users. I'm going to check behavior when the files are prepared outside of multistage docker. The other option is jib.

  20. anthonydahanne commented on May 13, 2024

    @anthonydahanne
    Contributor

    The other option is jib.

    Have you considered Paketo Buildpacks, the default Spring Boot container solution that supports CDS?

  21. wyhasany commented on May 13, 2024

    @wyhasany

    Unfortunately buildpacks images are bigger from the ones manually created.

  22. anthonydahanne commented on May 13, 2024

    @anthonydahanne
    Contributor

    well, I invite you to join the Paketo community: if you're interested in "small" images you'll learn about tiny builders, how to rebase on small run images, and if you're still unsatisfied, you'll learn about custom stack you could build with Chainguard, etc.

    See you there 👋

  23. wyhasany commented on May 15, 2024

    @wyhasany

    @wilkinsona Hmm... it seems to be not specific to the Docker:

    $ java -Djarmode=tools -jar spring-cold-startup-0.0.1-SNAPSHOT.jar extract --destination out --application-filename app.jar
    
    $ cd out
    
    $ tree -D
    [May 13 14:16]  .
    ├── [May 13 14:16]  application
    │   └── [May 13 14:16]  app.jar
    ├── [May 13 14:16]  dependencies
    │   └── [May 13 14:16]  lib
    │       ├── [Apr 23 15:16]  byte-buddy-1.14.13.jar
    │       ├── [Mar 19 13:53]  jackson-annotations-2.17.0.jar
    │       ├── [Mar 19 13:53]  jackson-core-2.17.0.jar
    │       ├── [Mar 19 13:53]  jackson-databind-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-datatype-jdk8-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-datatype-jsr310-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-module-parameter-names-2.17.0.jar
    │       ├── [May 13 11:34]  jakarta.annotation-api-2.1.1.jar
    │       ├── [Apr 23 15:16]  jul-to-slf4j-2.0.13.jar
    │       ├── [Apr 26 18:25]  log4j-api-2.23.1.jar
    │       ├── [Apr 26 18:25]  log4j-to-slf4j-2.23.1.jar
    │       ├── [Apr 23 10:25]  logback-classic-1.5.6.jar
    │       ├── [Apr 23 10:25]  logback-core-1.5.6.jar
    │       ├── [Apr 26 18:25]  micrometer-commons-1.13.0-RC1.jar
    │       ├── [Apr 26 18:25]  micrometer-observation-1.13.0-RC1.jar
    │       ├── [Apr 23 10:25]  slf4j-api-2.0.13.jar
    │       ├── [May 13 11:34]  snakeyaml-2.2.jar
    │       ├── [Apr 23 15:16]  spring-aop-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-beans-6.1.6.jar
    │       ├── [Apr 26 18:25]  spring-boot-3.3.0-RC1.jar
    │       ├── [Apr 26 18:25]  spring-boot-autoconfigure-3.3.0-RC1.jar
    │       ├── [Apr 23 15:16]  spring-context-6.1.6.jar
    │       ├── [Apr 16 12:10]  spring-core-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-expression-6.1.6.jar
    │       ├── [Apr 16 12:10]  spring-jcl-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-web-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-webmvc-6.1.6.jar
    │       ├── [Apr 23 15:16]  tomcat-embed-core-10.1.20.jar
    │       ├── [Apr 23 15:16]  tomcat-embed-el-10.1.20.jar
    │       └── [Apr 23 15:16]  tomcat-embed-websocket-10.1.20.jar
    ├── [May 13 14:16]  snapshot-dependencies
    └── [May 13 14:16]  spring-boot-loader
    
    $ cp -R application/ .
    
    $ cp -R dependencies/ .
    
    $ ls -la
    .rw-r--r-- 3.4k rowickim 15 May 16:09 app.jar
    drwxr-xr-x    - rowickim 13 May 14:16 application
    drwxr-xr-x    - rowickim 13 May 14:16 dependencies         
    drwxr-xr-x    - rowickim 15 May 16:10 lib            #date was changed after the copy, the very same goes for files underneath
    
    $ ls -la lib
    .rw-r--r-- 4.2M rowickim 15 May 16:10 byte-buddy-1.14.13.jar
    .rw-r--r--  78k rowickim 15 May 16:10 jackson-annotations-2.17.0.jar
    .rw-r--r-- 582k rowickim 15 May 16:10 jackson-core-2.17.0.jar
    .rw-r--r-- 1.6M rowickim 15 May 16:10 jackson-databind-2.17.0.jar
    .rw-r--r--  36k rowickim 15 May 16:10 jackson-datatype-jdk8-2.17.0.jar
    .rw-r--r-- 132k rowickim 15 May 16:10 jackson-datatype-jsr310-2.17.0.jar
    .rw-r--r--  10k rowickim 15 May 16:10 jackson-module-parameter-names-2.17.0.jar
    .rw-r--r--  26k rowickim 15 May 16:10 jakarta.annotation-api-2.1.1.jar
    .rw-r--r-- 6.3k rowickim 15 May 16:10 jul-to-slf4j-2.0.13.jar
    .rw-r--r-- 343k rowickim 15 May 16:10 log4j-api-2.23.1.jar
    #...
    
    $ java -Dspring.context.exit=onRefresh -XX:ArchiveClassesAtExit=app-cds.jsa -Xshare:on -jar app.jar
    
    $ rm -rf app.jar lib
    
    $ cp -R application/ .
    
    $ cp -R dependencies/ .
    
    $ java -XX:SharedArchiveFile=app-cds.jsa -Xshare:on -jar app.jar
    [0.123s][warning][cds] A jar file is not the one used while building the shared archive file: app.jar
    [0.123s][warning][cds] A jar file is not the one used while building the shared archive file: app.jar
    [0.123s][warning][cds] app.jar timestamp has changed.
    [0.123s][warning][cds,dynamic] Unable to use shared archive. The top archive failed to load: app-cds.jsa
    [0.124s][error  ][cds        ] An error has occurred while processing the shared archive file.
    [0.124s][error  ][cds        ] Unable to map shared spaces
    Error occurred during initialization of VM
    Unable to use shared archive.

    To fix that we can just preserve metadata of files during copy:
    https://man7.org/linux/man-pages/man1/cp.1.html

    $ rm -rf app.jar lib
    
    $ cp -pR application/ .
    
    $ cp -pR dependencies/ .
    
    [May 13 14:16]  .
    ├── [May 15 16:14]  app-cds.jsa
    ├── [May 13 14:16]  app.jar
    ├── [May 13 14:16]  application
    │   └── [May 13 14:16]  app.jar
    ├── [May 13 14:16]  dependencies
    │   └── [May 13 14:16]  lib
    │       ├── [Apr 23 15:16]  byte-buddy-1.14.13.jar
    │       ├── [Mar 19 13:53]  jackson-annotations-2.17.0.jar
    │       ├── [Mar 19 13:53]  jackson-core-2.17.0.jar
    │       ├── [Mar 19 13:53]  jackson-databind-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-datatype-jdk8-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-datatype-jsr310-2.17.0.jar
    │       ├── [Apr 26 18:25]  jackson-module-parameter-names-2.17.0.jar
    │       ├── [May 13 11:34]  jakarta.annotation-api-2.1.1.jar
    │       ├── [Apr 23 15:16]  jul-to-slf4j-2.0.13.jar
    │       ├── [Apr 26 18:25]  log4j-api-2.23.1.jar
    │       ├── [Apr 26 18:25]  log4j-to-slf4j-2.23.1.jar
    │       ├── [Apr 23 10:25]  logback-classic-1.5.6.jar
    │       ├── [Apr 23 10:25]  logback-core-1.5.6.jar
    │       ├── [Apr 26 18:25]  micrometer-commons-1.13.0-RC1.jar
    │       ├── [Apr 26 18:25]  micrometer-observation-1.13.0-RC1.jar
    │       ├── [Apr 23 10:25]  slf4j-api-2.0.13.jar
    │       ├── [May 13 11:34]  snakeyaml-2.2.jar
    │       ├── [Apr 23 15:16]  spring-aop-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-beans-6.1.6.jar
    │       ├── [Apr 26 18:25]  spring-boot-3.3.0-RC1.jar
    │       ├── [Apr 26 18:25]  spring-boot-autoconfigure-3.3.0-RC1.jar
    │       ├── [Apr 23 15:16]  spring-context-6.1.6.jar
    │       ├── [Apr 16 12:10]  spring-core-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-expression-6.1.6.jar
    │       ├── [Apr 16 12:10]  spring-jcl-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-web-6.1.6.jar
    │       ├── [Apr 23 15:16]  spring-webmvc-6.1.6.jar
    │       ├── [Apr 23 15:16]  tomcat-embed-core-10.1.20.jar
    │       ├── [Apr 23 15:16]  tomcat-embed-el-10.1.20.jar
    │       └── [Apr 23 15:16]  tomcat-embed-websocket-10.1.20.jar
    ├── [May 13 14:16]  lib
    │   ├── [Apr 23 15:16]  byte-buddy-1.14.13.jar
    │   ├── [Mar 19 13:53]  jackson-annotations-2.17.0.jar
    │   ├── [Mar 19 13:53]  jackson-core-2.17.0.jar
    │   ├── [Mar 19 13:53]  jackson-databind-2.17.0.jar
    │   ├── [Apr 26 18:25]  jackson-datatype-jdk8-2.17.0.jar
    │   ├── [Apr 26 18:25]  jackson-datatype-jsr310-2.17.0.jar
    │   ├── [Apr 26 18:25]  jackson-module-parameter-names-2.17.0.jar
    │   ├── [May 13 11:34]  jakarta.annotation-api-2.1.1.jar
    │   ├── [Apr 23 15:16]  jul-to-slf4j-2.0.13.jar
    │   ├── [Apr 26 18:25]  log4j-api-2.23.1.jar
    │   ├── [Apr 26 18:25]  log4j-to-slf4j-2.23.1.jar
    │   ├── [Apr 23 10:25]  logback-classic-1.5.6.jar
    │   ├── [Apr 23 10:25]  logback-core-1.5.6.jar
    │   ├── [Apr 26 18:25]  micrometer-commons-1.13.0-RC1.jar
    │   ├── [Apr 26 18:25]  micrometer-observation-1.13.0-RC1.jar
    │   ├── [Apr 23 10:25]  slf4j-api-2.0.13.jar
    │   ├── [May 13 11:34]  snakeyaml-2.2.jar
    │   ├── [Apr 23 15:16]  spring-aop-6.1.6.jar
    │   ├── [Apr 23 15:16]  spring-beans-6.1.6.jar
    │   ├── [Apr 26 18:25]  spring-boot-3.3.0-RC1.jar
    │   ├── [Apr 26 18:25]  spring-boot-autoconfigure-3.3.0-RC1.jar
    │   ├── [Apr 23 15:16]  spring-context-6.1.6.jar
    │   ├── [Apr 16 12:10]  spring-core-6.1.6.jar
    │   ├── [Apr 23 15:16]  spring-expression-6.1.6.jar
    │   ├── [Apr 16 12:10]  spring-jcl-6.1.6.jar
    │   ├── [Apr 23 15:16]  spring-web-6.1.6.jar
    │   ├── [Apr 23 15:16]  spring-webmvc-6.1.6.jar
    │   ├── [Apr 23 15:16]  tomcat-embed-core-10.1.20.jar
    │   ├── [Apr 23 15:16]  tomcat-embed-el-10.1.20.jar
    │   └── [Apr 23 15:16]  tomcat-embed-websocket-10.1.20.jar
    ├── [May 13 14:16]  snapshot-dependencies
    └── [May 13 14:16]  spring-boot-loader
    
    $ rm app-cds.jsa
    
    $ java -Dspring.context.exit=onRefresh -XX:ArchiveClassesAtExit=app-cds.jsa -Xshare:on -jar app.jar 
    
    $ rm -rf app.jar lib
    
    $ cp -pR application/ .
    
    $ cp -pR dependencies/ .
    
    $ java -XX:SharedArchiveFile=app-cds.jsa -Xshare:on -jar app.jar 
      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
    
     :: Spring Boot ::            (v3.3.0-RC1)
    
    2024-05-15T16:27:32.998+02:00  INFO 5878 --- [           main] t.p.cold.SpringColdStartupApplication    : Starting SpringColdStartupApplication v0.0.1-SNAPSHOT using Java 21.0.2 with PID 5878

    Let's try with Dockerfile:

    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.3-10-cds AS builder
    WORKDIR application
    COPY build/libs/*.jar app.jar
    RUN java -Djarmode=tools -jar app.jar extract --layers --destination out --application-filename app.jar
    RUN cp -pR ./out/dependencies/* ./
    #RUN cp -pR ./out/spring-boot-loader/* ./
    #RUN cp -pR ./out/snapshot-dependencies/* ./
    RUN cp -pR ./out/application/* ./
    RUN java -Xshare:dump #-XX:+UseZGC
    RUN java \
        -Dspring.context.exit=onRefresh \
        -XX:ArchiveClassesAtExit=/application/app-cds.jsa \
        -Xshare:on \
        -jar app.jar
    
    FROM --platform=linux/arm64/v8 bellsoft/liberica-openjre-alpine-musl:21.0.3-10-cds
    WORKDIR application
    
    COPY --from=builder /usr/lib/jvm/jre/lib/server/classes.jsa /usr/lib/jvm/jre/lib/server/classes.jsa
    COPY --from=builder application/out/dependencies/ ./
    COPY --from=builder application/out/spring-boot-loader/ ./
    COPY --from=builder application/out/snapshot-dependencies/ ./
    COPY --from=builder application/out/application/ ./
    
    COPY --from=builder application/app-cds.jsa /application/app-cds.jsa
    ENTRYPOINT ["java", "-XX:SharedArchiveFile=/usr/lib/jvm/jre/lib/server/classes.jsa:app-cds.jsa", "-Xshare:on", "-jar", "app.jar"]

    it works as expected using correct jars. Based on that this time the issue is not with the docker but missing -p preserve flag on coping files for generation of class data sharing archive. I think it is worth of mentioning in documentation to avoid complaining users.

  24. wilkinsona commented on May 15, 2024

    @wilkinsona
    Member

    Very interesting. Thank you, @wyhasany. Let me discuss it with the team to see if we think it would be best documented in Boot's docs, Framework's docs, or perhaps even in both.

  25. removed
    for: team-meetingAn issue we'd like to discuss as a team to make progress
    on Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions