Skip to content

shrinkwrap/shrinkwrap-springboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot ShrinkWrap Archive

This specific ShrinkWrap archive allows you to create Spring Boot archives. The basic archive is class is org.shrinkwrap.springboot.api.spec.SpringBootArchive.

Spring Boot Archive layout

Spring Boot has used different layouts in different versions. As a result, the first action required before adding any resource to a SpringBootArchive is to set the layout. It is important to set the layout according to the Spring Boot version that is going to be added as libraries to the archive. By default the archive will use the original layout used from versions 1.0.x to 1.3.x. You can set a different layout by using the setSpringBootLayout method.

The standard formats used by Spring Boot are defined as constants in the class org.shrinkwrap.springboot.impl.SpringBootLayouts.

Custom layout are also possible by implementing the org.shrinkwrap.springboot.SpringBootLayout interface. Notice that you define a custom layout, it won’t be recognized by the default launcher class, you would also need to implement your own Spring Boot launcher implementation class. An example can be seen by looking at SpringBootTest.should_create_custom_spring_boot_15jar_archive() test method.

Spring Boot Archive usage

To create a Spring Boot archive, you need to pass org.shrinkwrap.springboot.api.spec.SpringBootArchive to the ShrinkWrap.create method.

ShrinkWrap.create(SpringBootArchive.class)
        .setSpringBootLayout(SpringBootLayouts.SPRING_BOOT_14) // (1)

        .addClasses(Application.class, .HelloController.class) // (2)

        .addAsLibraries(Maven.resolver()
                   .resolve("org.springframework.boot:spring-boot-starter-web:1.4.4.RELEASE")
                   .withTransitivity()
                   .as(JavaArchive.class)
        ) // (3)

       .addAsLauncherLibraries(Maven.resolver()
                    .resolve("org.springframework.boot:spring-boot-loader:1.4.4.RELEASE")
                    .withTransitivity()
                    .as(JavaArchive.class)
       ) // (4)

       .addAsWebResource(new StringAsset("world"), "hello") // (5)

       .setSpringBootManifest(Application.class.getName(), "1.4.4.RELEASE"); // (6)
  1. First step must be setting the file layout

  2. Classes can be added in the same way as a JavaArchive

  3. Libraries must be bundled inside the archive (in a libraries directory). addAsLibraries adds them in correct place.

  4. Spring Boot applications need a launcher to run.

  5. Applications can optionally contain static web resources. addAsWebResource allows adding any static web resource, similar to WebArchive.

  6. As in the case of an executable JavaArchive, A Spring Boot application requires a manifest. setSpringBootManifest method prepares a manifest in the expected format.

Notice that the layout, the application libraries, the launcher, and the manifest all reference exactly the same Spring Boot version.

Important
To materialize a Spring Boot application, you need to use ZipStoredExporter, for example springBootArchive.as(ZipStoredExporter.class).exportTo(new File("/tmp/app.jar")); See SpringBootTest.validateSpringBootArchive(…​) for an example.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages