├── .github ├── dependabot.yml └── workflows │ ├── add-to-projects.yml │ ├── test.yml │ └── triggerConversion.yml ├── .gitignore ├── CONTRIBUTING.md ├── README.adoc ├── finish ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── springboot │ │ │ ├── Application.java │ │ │ └── HelloController.java │ └── liberty │ │ ├── config │ │ └── server.xml │ │ └── instantOn │ │ └── crac.xml │ └── test │ └── java │ └── com │ └── example │ └── springboot │ ├── HelloControllerIT.java │ └── HelloControllerTest.java ├── instantOn └── Dockerfile ├── scripts ├── dailyBuild.sh ├── dockerImageTest.sh └── testApp.sh └── start ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ └── springboot │ │ ├── Application.java │ │ └── HelloController.java └── liberty │ ├── config │ └── .gitkeep │ └── instantOn │ └── crac.xml └── test └── java └── com └── example └── springboot ├── HelloControllerIT.java └── HelloControllerTest.java /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/finish" 5 | schedule: 6 | interval: monthly 7 | open-pull-requests-limit: 50 8 | - package-ecosystem: maven 9 | directory: "/start" 10 | schedule: 11 | interval: monthly 12 | open-pull-requests-limit: 50 13 | -------------------------------------------------------------------------------- /.github/workflows/add-to-projects.yml: -------------------------------------------------------------------------------- 1 | name: Add issues to Liberty guides backlog project 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - transferred 8 | 9 | jobs: 10 | add-to-project: 11 | name: Add issue to backlog 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/add-to-project@v0.4.0 15 | with: 16 | project-url: https://github.com/orgs/OpenLiberty/projects/11 17 | github-token: ${{ secrets.ADMIN_BACKLOG }} 18 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test application 2 | 3 | on: 4 | pull_request: 5 | branches: [ prod, staging ] 6 | 7 | jobs: 8 | check-files: 9 | if: ${{ github.event_name == 'pull_request' }} 10 | runs-on: ubuntu-latest 11 | outputs: 12 | canSkip: ${{ steps.Checker.outputs.canSkip }} 13 | steps: 14 | - name: Get files 15 | uses: actions/checkout@v4 16 | - name: Get tools 17 | uses: actions/checkout@v4 18 | with: 19 | path: tools/ 20 | repository: openliberty/guides-common 21 | - id: Checker 22 | shell: bash 23 | run: bash ./tools/pr-checker/checker.sh ${{ github.repository }} ${{ github.event.pull_request.number }} | tee checker.log 24 | - id: Lint-Code-Base 25 | if: always() 26 | uses: github/super-linter@latest 27 | env: 28 | VALIDATE_ALL_CODEBASE: false 29 | VALIDATE_BASH: false 30 | VALIDATE_JAVA: false 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | LINTER_RULES_PATH: ./tools/pr-checker/linters/ 33 | DEFAULT_BRANCH: prod 34 | - name: Summary 35 | if: always() 36 | run: | 37 | < ./checker.log tail -n +2; echo "====== Super Linter ======" 38 | < ./super-linter.log sed -n '/.*The script has completed.*/,$p' | tail -n +4 | sed 's/.*\(\[[A-Z]\+\]\)/\1/' 39 | echo "====== Examine logs in Checker and Super-Linter steps for more details ======" 40 | if [ '${{ steps.Checker.outcome }}' != 'success' ] || [ '${{ steps.Lint-Code-Base.outcome }}' != 'success' ]; then exit 1; fi 41 | test-app: 42 | runs-on: ubuntu-latest 43 | needs: [check-files] 44 | if: "!contains(needs.check-files.outputs.canSkip, 'true')" 45 | defaults: 46 | run: 47 | working-directory: finish 48 | 49 | steps: 50 | - uses: actions/checkout@v4 51 | - name: Set up JDK 21 52 | uses: actions/setup-java@v3 53 | with: 54 | distribution: 'semeru' 55 | java-version: 21 56 | - run: unset _JAVA_OPTIONS 57 | - name: Run tests 58 | run: sudo -E ../scripts/testApp.sh 59 | - name: Post tests 60 | if: always() 61 | run: | 62 | uname -r 63 | logsPath=$(sudo find . -name "console.log"); 64 | sudo cat "$logsPath" | sudo grep Launching 65 | - name: Archive server logs if failed 66 | if: failure() 67 | uses: actions/upload-artifact@v4 68 | with: 69 | name: server-logs 70 | path: finish/target/liberty/wlp/usr/servers/defaultServer/logs/ 71 | -------------------------------------------------------------------------------- /.github/workflows/triggerConversion.yml: -------------------------------------------------------------------------------- 1 | name: Rebuild cloud-hosted guide 2 | 3 | # Controls when the action will run. Triggers the workflow on push 4 | # events but only for the main branch 5 | on: 6 | push: 7 | branches: 8 | - 'prod' 9 | - 'staging' 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | # This workflow contains a single job called "post" 14 | post: 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | # Steps represent a sequence of tasks that will be executed as part of the job 19 | steps: 20 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 21 | # Uses the secrets from the organisation for credentials 22 | - uses: actions/checkout@v2 23 | 24 | - name: Invoke workflow in another repo with inputs 25 | uses: benc-uk/workflow-dispatch@v1 26 | with: 27 | workflow: GuideConverter 28 | repo: OpenLiberty/cloud-hosted-guides 29 | token: ${{ secrets.GUIDECONVERSIONTOOL_PASSWORD }} 30 | inputs: '{ "branch": "${{ github.ref }}", "guide_name": "${{ github.event.repository.name }}" }' 31 | ref: "refs/heads/prod" 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | bin/ 3 | .project 4 | .settings 5 | .classpath 6 | .factorypath 7 | .idea/ 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Open Liberty guides 2 | 3 | Anyone can contribute to the Open Liberty guides and we welcome your contributions! 4 | 5 | There are multiple ways to contribute: report bugs, fix bugs, contribute code, improve upon documentation, etc. 6 | 7 | ## Raising issues 8 | 9 | Please raise any bug reports in this [guide repository](../../issues). For new topics, large updates to existing guides, or general suggestions and ideas, report your issue in the [Open Liberty common guides repository](https://github.com/OpenLiberty/guides-common/issues). Be sure to search the list of open issues to see if your issue has already been raised. 10 | 11 | A good bug report makes it easy for everyone to understand what you were trying to do and what went wrong. Provide as much context as possible so we can try to recreate the issue. 12 | 13 | ## Contributions 14 | 15 | Contributing to an Open Liberty guide is simple. Each guide is maintained in its own GitHub repository. To contribute, just fork from the `prod` branch for your chosen guide. Then create a branch in your forked repository to include your contribution and open a pull request to the `staging` branch for the guide. 16 | Certify the originality of your work by following the [Developer Certificate of Origin (DCO)](https://developercertificate.org) approach and adding a line to the end of the Git commit message to sign your work: 17 | 18 | ```text 19 | Signed-off-by: Jane Williams 20 | ``` 21 | 22 | The sign-off is just a line at the end of the commit message that certifies that you wrote it or otherwise have the right to pass it on as an open source patch. 23 | 24 | Use your real name when you sign. We can't accept pseudonyms or anonymous contributions. 25 | 26 | Many Git UI tools have support for adding the `Signed-off-by` line to the end of your commit message. This line can be automatically added by the `git commit` command by using the `-s` option. 27 | 28 | The team is then notified and your contribution is reviewed according to the following process: 29 | 30 | 1. The team will review your change(s). 31 | - If there are further changes to be made, the team will request changes on the pull request. 32 | - If the team does not agree with the change, the PR will be closed with an explanation and suggestion for follow-up. 33 | 2. If the team approves, the team will merge your PR. A full Open Liberty staging site build will be run. 34 | 3. Based on the results of the build: 35 | - If further review is needed, we will let you know about a pending review from our team and discuss any necessary improvements that need to be made to your change(s). 36 | - If everything is successful, the team will publish your change(s) to the `prod` branch and update the Open Liberty production site, if necessary. 37 | 38 | ## Questions and concerns 39 | 40 | If you have any questions or concerns about the guides or about Open Liberty, you can visit [Gitter for Open Liberty](https://gitter.im/OpenLiberty/) and post your questions in the relevant rooms. You can also join the Open Liberty group on [Groups.io](https://groups.io/g/openliberty) to discuss any issues you have. 41 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, 2025 IBM Corporation and others. 2 | // Licensed under Creative Commons Attribution-NoDerivatives 3 | // 4.0 International (CC BY-ND 4.0) 4 | // https://creativecommons.org/licenses/by-nd/4.0/ 5 | // 6 | // Contributors: 7 | // IBM Corporation 8 | // 9 | :page-layout: guide-multipane 10 | :projectid: spring-boot 11 | :page-duration: 20 minutes 12 | :page-releasedate: 2019-11-04 13 | :page-majorupdateddate: 2025-01-09 14 | :page-description: Learn how to containerize, package, and run a Spring Boot application on Open Liberty. 15 | :page-tags: ['docker'] 16 | :page-related-guides: ['rest-intro', 'containerize'] 17 | :page-permalink: /guides/{projectid} 18 | :common-includes: https://raw.githubusercontent.com/OpenLiberty/guides-common/prod 19 | :source-highlighter: prettify 20 | :page-seo-title: Deploying a Spring Boot application 21 | :page-seo-description: A tutorial with examples on how to containerize, package, and run a Spring Boot application in a Docker container on an Open Liberty server. 22 | :guide-author: Open Liberty 23 | = Containerizing, packaging, and running a Spring Boot application 24 | 25 | [.hidden] 26 | NOTE: This repository contains the guide documentation source. To view the guide in published form, view it on the https://openliberty.io/guides/{projectid}.html[Open Liberty website]. 27 | 28 | Learn how to containerize, package, and run a Spring Boot application on Open Liberty without modification. 29 | 30 | == What you'll learn 31 | 32 | The starting point of this guide is the finished application from the https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot^] guide. If you are not familiar with Spring Boot, complete that guide first. Java 21 is required to run this project. 33 | 34 | You will learn how to use the `springBootUtility` command to deploy a Spring Boot application in Docker on Open Liberty without modification. This command stores the dependent library JAR files of the application to the target library cache, and packages the remaining application artifacts into a thin application JAR file. Optionally, you will learn how to use Liberty InstantOn with your Spring Boot application for faster startup. 35 | 36 | You will also learn how to run the Spring Boot application locally with Open Liberty, and how to package it so that it is embedded with an Open Liberty server package. 37 | 38 | [role='command'] 39 | include::{common-includes}/gitclone.adoc[] 40 | 41 | 42 | == Building and running the application 43 | 44 | First, build the initial Spring Boot application into an executable JAR file. Navigate to the `start` directory and run the Maven package command: 45 | 46 | include::{common-includes}/os-tabs.adoc[] 47 | 48 | [.tab_content.windows_section] 49 | -- 50 | [role='command'] 51 | ``` 52 | cd start 53 | mvnw.cmd package 54 | ``` 55 | -- 56 | 57 | [.tab_content.mac_section] 58 | -- 59 | [role='command'] 60 | ``` 61 | cd start 62 | ./mvnw package 63 | ``` 64 | -- 65 | 66 | [.tab_content.linux_section] 67 | -- 68 | [role='command'] 69 | ``` 70 | cd start 71 | ./mvnw package 72 | ``` 73 | -- 74 | 75 | You can now run the application in the embedded Tomcat web container by executing the JAR file that you built: 76 | 77 | [role='command'] 78 | ``` 79 | java -jar target/guide-spring-boot-0.1.0.jar 80 | ``` 81 | 82 | After you see the following messages, the application is ready: 83 | [role='no_copy'] 84 | ---- 85 | ... INFO ... [ main] com.example.springboot.Application : Started Application in 2.511 seconds (process running for 3.24) 86 | Let's inspect the beans provided by Spring Boot: 87 | application 88 | ... 89 | welcomePageHandlerMapping 90 | welcomePageNotAcceptableHandlerMapping 91 | ---- 92 | 93 | // Static guide instruction 94 | ifndef::cloud-hosted[] 95 | Go to the http://localhost:8080/hello[^] URL to access the application. 96 | 97 | The following output is displayed in your browser: 98 | [role='no_copy'] 99 | ---- 100 | Greetings from Spring Boot! 101 | ---- 102 | endif::[] 103 | 104 | // Cloud hosted guide instruction 105 | ifdef::cloud-hosted[] 106 | Open another command-line session by selecting **Terminal** > **New Terminal** from the menu of the IDE. Run the following command to access the application: 107 | ```bash 108 | curl http://localhost:8080/hello 109 | ``` 110 | 111 | The following output is returned: 112 | ``` 113 | Greetings from Spring Boot! 114 | ``` 115 | endif::[] 116 | 117 | When you need to stop the application, press `CTRL+C` in the command-line session where you ran the application. 118 | 119 | == Building and running the application in a Docker container 120 | 121 | You will build an Open Liberty Docker image to run the Spring Boot application. Using Docker, you can run your thinned application with a few simple commands. For more information on using Open Liberty with Docker, see the https://openliberty.io/guides/containerize.html[Containerizing microservices^] guide. 122 | 123 | Learn more about Docker on the https://www.docker.com/why-docker[official Docker website^]. 124 | 125 | Install Docker by following the instructions in the https://docs.docker.com/engine/install[official Docker documentation^]. 126 | 127 | Navigate to the `start` directory. 128 | 129 | [role="code_command hotspot file=0", subs="quotes"] 130 | ---- 131 | #Create the `Dockerfile` in the `start` directory.# 132 | `Dockerfile` 133 | ---- 134 | 135 | Dockerfile 136 | [source, Text, linenums, role='code_column'] 137 | ---- 138 | include::finish/Dockerfile[] 139 | ---- 140 | 141 | This Dockerfile is written in two main stages. For more information about multi-stage Dockerfiles, see the documentation on the https://docs.docker.com/develop/develop-images/multistage-build/[official Docker website^]. 142 | 143 | The first stage copies the [hotspot=copyJar]`guide-spring-boot-0.1.0.jar` Spring Boot application to the [hotspot=7 file=0]`/staging` temporary directory, 144 | and then uses the Open Liberty [hotspot=springBootUtility]`springBootUtility` command to thin the application. For more information about the `springBootUtility` command, see the https://openliberty.io/docs/latest/reference/command/springbootUtility-thin.html[springBootUtility documentation^]. 145 | 146 | The second stage begins with the [hotspot=OLimage2 file=0]`Open Liberty Docker image`. The Dockerfile copies the Liberty [hotspot=serverXml file=0]`server.xml` configuration file from the `/opt/ol/wlp/templates` directory, which enables Spring Boot and TLS support. Then, the Dockerfile copies the Spring Boot dependent library JAR files that are at the [hotspot=libcache file=0]`lib.index.cache` directory and the [hotspot=thinjar file=0]`thin-guide-spring-boot-0.1.0.jar` file. The `lib.index.cache` directory and the `thin-guide-spring-boot-0.1.0.jar` file were both generated in the first stage. 147 | 148 | 149 | 150 | Use the following command to build the Docker image: 151 | [role='command'] 152 | ``` 153 | docker build -t springboot . 154 | ``` 155 | 156 | To verify that the images are built, run the `docker images` command to list all local Docker images: 157 | 158 | [role='command'] 159 | ``` 160 | docker images 161 | ``` 162 | 163 | Your `springboot` image appears in the list of Docker images: 164 | [role='no_copy'] 165 | ``` 166 | REPOSITORY TAG IMAGE ID CREATED SIZE 167 | springboot latest 3a5492c0cbeb 27 seconds ago 485MB 168 | ``` 169 | 170 | Now, you can run the Spring Boot application in a Docker container: 171 | [role='command'] 172 | ``` 173 | docker run -d --name springBootContainer --rm -p 9080:9080 -p 9443:9443 springboot 174 | ``` 175 | 176 | Before you access your application from the browser, run the `docker ps` command to make sure that your container is running: 177 | 178 | [role='command'] 179 | ---- 180 | docker ps 181 | ---- 182 | 183 | You see an entry similar to the following example: 184 | [role='no_copy'] 185 | ---- 186 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 187 | e33532aa07d6 springboot "/opt/ol/helpers/run…" 7 seconds ago Up 2 seconds 0.0.0.0:9080->9080/tcp, 0.0.0.0:9443->9443/tcp springBootContainer 188 | ---- 189 | 190 | You can watch the application start by monitoring the logs: 191 | [role='command'] 192 | ``` 193 | docker logs springBootContainer 194 | ``` 195 | 196 | Wait several seconds for the following message, which indicates that Liberty’s startup is complete: 197 | [role='no_copy'] 198 | ---- 199 | ... 200 | CWWKZ0001I: Application thin-guide-spring-boot-0.1.0 started in 8.033 seconds. 201 | ... 202 | CWWKF0011I: The defaultServer server is ready to run a smarter planet. 203 | The defaultServer server started in 11.065 seconds. 204 | ---- 205 | 206 | Note that the `thin-guide-spring-boot-0.1.0` application took 8.033 seconds to start. 207 | 208 | // Static guide instruction 209 | ifndef::cloud-hosted[] 210 | After the application starts, go to the http://localhost:9080/hello[^] URL to access the application. 211 | endif::[] 212 | 213 | // Cloud hosted guide instruction 214 | ifdef::cloud-hosted[] 215 | After the application starts, run the following command to access the application: 216 | 217 | ```bash 218 | curl http://localhost:9080/hello 219 | ``` 220 | endif::[] 221 | 222 | After you are finished checking out the application, stop your container by running the following command: 223 | 224 | [role='command'] 225 | ``` 226 | docker stop springBootContainer 227 | ``` 228 | 229 | ifndef::cloud-hosted[] 230 | == Optional: Faster container startup with InstantOn 231 | 232 | Liberty InstantOn provides fast startup times for MicroProfile and Jakarta EE applications. In this section, you’ll learn how to build an InstantOn image that provides fast startup times. Your application can start in milliseconds, without compromising on throughput, memory, development-production parity, or Java language features. 233 | 234 | Liberty InstantOn requires a Linux system with kernel version 5.9 or greater. You can run the following command to check the kernel version of your system: 235 | 236 | [role='command'] 237 | ``` 238 | uname -r 239 | ``` 240 | 241 | If your kernel version is older than 5.9, you can skip this section and move on to the <> section. 242 | 243 | The https://openliberty.io/docs/latest/reference/feature/crac.html[Coordinated Restore at Checkpoint^] (`crac`) Liberty feature enables applications to use the Liberty InstantOn implementation of the https://javadoc.io/doc/org.crac/crac/1.4.0/index.html[org.crac^] APIs. When the `org.crac` APIs are enabled, checkpoint and restore can work with applications written using the Spring Framework. 244 | 245 | [role="code_command hotspot file=0", subs="quotes"] 246 | ---- 247 | #Replace the `Dockerfile` in the `start` directory.# 248 | `Dockerfile` 249 | ---- 250 | 251 | Dockerfile 252 | [source, Text, linenums, role='code_column'] 253 | ---- 254 | include::instantOn/Dockerfile[] 255 | ---- 256 | 257 | crac.xml 258 | [source, xml, linenums, role='code_column'] 259 | ---- 260 | include::finish/src/main/liberty/instantOn/crac.xml[] 261 | ---- 262 | 263 | The [hotspot=cracXml file=0]`COPY` command copies the provided `crac.xml` configuration file to the Liberty `configDropins` configuration directory. The `crac.xml` file enables the [hotspot=crac file=1]`crac` feature to the Liberty instance. 264 | 265 | Run the following command to rebuild the Docker image: 266 | [role='command'] 267 | ``` 268 | docker build -t springboot . 269 | ``` 270 | 271 | To take a checkpoint of the application process with the `afterAppStart` option, run the following command: 272 | 273 | [role='command'] 274 | ``` 275 | docker run \ 276 | --name springBootCheckpointContainer \ 277 | --privileged \ 278 | --env WLP_CHECKPOINT=afterAppStart \ 279 | springboot 280 | ``` 281 | 282 | When the application process checkpoint completes, the `springBootCheckpointContainer` application container is stopped and exits. The stopped `springBootCheckpointContainer` container contains the data from the InstantOn checkpoint process. Take this checkpoint process data and commit it to an application container image layer called `springboot-instanton`, run the following commands: 283 | 284 | [role='command'] 285 | ``` 286 | docker commit springBootCheckpointContainer springboot-instanton 287 | docker rm springBootCheckpointContainer 288 | ``` 289 | 290 | The stopped `springBootCheckpointContainer` container is no longer needed and can safely be removed. 291 | 292 | To verify that the InstantOn image is built, run the `docker images` command to list all local Docker images: 293 | 294 | [role='command'] 295 | ``` 296 | docker images 297 | ``` 298 | 299 | Your `springboot-instanton` image appears in the list of Docker images. 300 | 301 | [role='no_copy'] 302 | ``` 303 | REPOSITORY TAG IMAGE ID CREATED SIZE 304 | springboot-instanton latest c4aabcdd64bf 20 seconds ago 583MB 305 | springboot latest 3a5492c0cbeb 14 minutes ago 484MB 306 | ``` 307 | 308 | Run the `springboot-instanton` InstantOn application image by running the following command: 309 | 310 | [role='command'] 311 | ``` 312 | docker run \ 313 | --rm -d \ 314 | --name springBootContainer \ 315 | --cap-add=CHECKPOINT_RESTORE \ 316 | --cap-add=SETPCAP \ 317 | --security-opt seccomp=unconfined \ 318 | -p 9080:9080 \ 319 | springboot-instanton 320 | ``` 321 | 322 | Run the following command to see the container logs: 323 | 324 | [role='command'] 325 | ``` 326 | docker logs springBootContainer 327 | ``` 328 | 329 | You see more logs from Spring for restoring. Liberty’s startup is complete in less than a second. It shows a faster startup time of 0.874 seconds than the original `springboot` image that you built in the previous section. 330 | 331 | [role='no_copy'] 332 | ---- 333 | 2024-11-22T16:33:43.349Z INFO 1027 --- [ecutor-thread-1] o.s.c.support.DefaultLifecycleProcessor : Restarting Spring-managed lifecycle beans after JVM restore 334 | ... 335 | 2024-11-22T16:33:43.562Z INFO 1027 --- [ecutor-thread-1] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 135784 ms 336 | 2024-11-22T16:33:43.568Z INFO 1027 --- [ecutor-thread-1] o.s.c.support.DefaultLifecycleProcessor : Spring-managed lifecycle restart completed (restored JVM running for 525 ms) 337 | ... 338 | CWWKZ0001I: Application thin-guide-spring-boot-0.1.0 started in 0.874 seconds. 339 | ... 340 | CWWKF0011I: The defaultServer server is ready to run a smarter planet. 341 | The defaultServer server started in 0.897 seconds. 342 | ---- 343 | 344 | Go to the http://localhost:9080/hello[^] URL to access the application. 345 | 346 | After you are finished checking out the application, stop your container by running the following command: 347 | 348 | [role='command'] 349 | ``` 350 | docker stop springBootContainer 351 | ``` 352 | 353 | If you use Podman instead of Docker, you can build your InstantOn image in a simplified way. Read the https://openliberty.io/docs/latest/instanton.html#checkpoint_script[Building the InstantOn image with Podman and the checkpoint.sh script^] documentation. 354 | 355 | To learn more about the Liberty InstantOn feature, see the https://openliberty.io/docs/latest/instanton.html[Faster startup for containerized applications with Open Liberty InstantOn^] documentation. 356 | 357 | endif::[] 358 | 359 | 360 | == Running the application on Open Liberty 361 | 362 | Next, you will run the Spring Boot application locally on Open Liberty by updating the `pom.xml` file. 363 | 364 | The [hotspot file=0]`pom.xml` was created for you in this directory. 365 | 366 | [role="code_command hotspot file=0", subs="quotes"] 367 | ---- 368 | #Update the `Maven POM` file in the `start` directory.# 369 | `pom.xml` 370 | ---- 371 | 372 | pom.xml 373 | [source, XML, linenums, role='code_column hide_tags=packageFile,include,packageGoals'] 374 | ---- 375 | include::finish/pom.xml[] 376 | ---- 377 | 378 | [role="edit_command_text"] 379 | Add the [hotspot=libertyMavenPlugin file=0]`liberty-maven-plugin` to the [hotspot file=0]`pom.xml` file. 380 | 381 | The `liberty-maven-plugin` downloads and installs Open Liberty to the `target/liberty` directory. The [hotspot=installAppPackages file=0]`installAppPackages` configuration element in the [hotspot file=0]`pom.xml` file typically takes in the following parameters: `dependencies`, `project`, or `all`. The default value is `dependencies`, but to install the Spring Boot application to Open Liberty, the value must be [hotspot=installAppPackages file=0]`spring-boot-project`. This value allows Maven to package, thin, and copy the `guide-spring-boot-0.1.0.jar` application to the Open Liberty runtime [hotspot=appsDirectory file=0]`applications` directory and shared library directory. 382 | 383 | To run the Spring Boot application, the Open Liberty instance needs to be correctly configured. By default, the `liberty-maven-plugin` picks up the Liberty `server.xml` configuration file from the `src/main/liberty/config` directory. 384 | 385 | [role="code_command hotspot file=1", subs="quotes"] 386 | ---- 387 | #Create the Liberty `server.xml` configuration file.# 388 | `src/main/liberty/config/server.xml` 389 | ---- 390 | 391 | server.xml 392 | [source, XML, linenums, role='code_column'] 393 | ---- 394 | include::finish/src/main/liberty/config/server.xml[] 395 | ---- 396 | 397 | The [hotspot=servlet file=1]`servlet` and [hotspot=springboot file=1]`springBoot` features are required for the Liberty instance to run the Spring Boot application. The application port is specified as [hotspot=httpport file=1]`9080` and the application is configured as a [hotspot=springBootApplication file=1]`springBootApplication` element. For more information, see the https://www.openliberty.io/docs/latest/reference/config/springBootApplication.html[springBootApplication element documentation^]. 398 | 399 | If you didn't build the Spring Boot application, run the `package` goal: 400 | 401 | include::{common-includes}/os-tabs.adoc[] 402 | 403 | [.tab_content.windows_section] 404 | -- 405 | [role='command'] 406 | ``` 407 | mvnw.cmd package 408 | ``` 409 | -- 410 | 411 | [.tab_content.mac_section] 412 | -- 413 | [role='command'] 414 | ``` 415 | ./mvnw package 416 | ``` 417 | -- 418 | 419 | [.tab_content.linux_section] 420 | -- 421 | [role='command'] 422 | ``` 423 | ./mvnw package 424 | ``` 425 | -- 426 | 427 | Next, run the `liberty:run` goal. This goal creates the Open Liberty instance, installs required features, deploys the Spring Boot application to the Open Liberty instance, and starts the application. 428 | 429 | include::{common-includes}/os-tabs.adoc[] 430 | 431 | [.tab_content.windows_section] 432 | -- 433 | [role='command'] 434 | ``` 435 | mvnw.cmd liberty:run 436 | ``` 437 | -- 438 | 439 | [.tab_content.mac_section] 440 | -- 441 | [role='command'] 442 | ``` 443 | ./mvnw liberty:run 444 | ``` 445 | -- 446 | 447 | [.tab_content.linux_section] 448 | -- 449 | [role='command'] 450 | ``` 451 | ./mvnw liberty:run 452 | ``` 453 | -- 454 | 455 | After you see the following message, your Liberty instance is ready: 456 | [role="no_copy"] 457 | ---- 458 | The defaultServer server is ready to run a smarter planet. 459 | ---- 460 | 461 | // Static guide instruction 462 | ifndef::cloud-hosted[] 463 | Go to the http://localhost:9080/hello[^] URL to access the application. 464 | endif::[] 465 | 466 | // Cloud hosted guide instruction 467 | ifdef::cloud-hosted[] 468 | In another command-line sesssion, run the following command to access the application: 469 | 470 | ```bash 471 | curl http://localhost:9080/hello 472 | ``` 473 | endif::[] 474 | 475 | After you finish exploring the application, press `CTRL+C` to stop the Open Liberty instance. Alternatively, you can run the `liberty:stop` goal from the `start` directory in a separate command-line session: 476 | 477 | include::{common-includes}/os-tabs.adoc[] 478 | 479 | [.tab_content.windows_section] 480 | -- 481 | [role='command'] 482 | ``` 483 | mvnw.cmd liberty:stop 484 | ``` 485 | -- 486 | 487 | [.tab_content.mac_section] 488 | -- 489 | [role='command'] 490 | ``` 491 | ./mvnw liberty:stop 492 | ``` 493 | -- 494 | 495 | [.tab_content.linux_section] 496 | -- 497 | [role='command'] 498 | ``` 499 | ./mvnw liberty:stop 500 | ``` 501 | -- 502 | 503 | == Packaging the application embedded with Open Liberty 504 | 505 | You can update the `pom.xml` file to bind more Open Liberty Maven goals to the package phase. Binding these goals to the package phase allows the Maven `package` goal to build a Spring Boot application that is embedded with Open Liberty. 506 | 507 | [role="code_command hotspot file=0", subs="quotes"] 508 | ---- 509 | #Update the Maven POM file in the `start` directory.# 510 | `pom.xml` 511 | ---- 512 | 513 | pom.xml 514 | [source, XML, linenums, role='code_column'] 515 | ---- 516 | include::finish/pom.xml[] 517 | ---- 518 | 519 | [role="edit_command_text"] 520 | Add the [hotspot=include file=0]`include` and [hotspot=packageFile file=0]`packageName` configuration elements, and the [hotspot=packageGoals file=0]`executions` element to the `pom.xml` file. 521 | 522 | The [hotspot=include file=0]`include` configuration element specifies the `minify, runnable` values. The `runnable` value allows the application to be generated as a runnable JAR file. The `minify` value packages only what you need from your configuration files without bundling the entire Open Liberty install. 523 | 524 | The [hotspot=packageFile file=0]`packageName` configuration element specifies that the application is generated as a `GSSpringBootApp.jar` file. 525 | 526 | The [hotspot=packageGoals file=0]`executions` element specifies the required Open Liberty Maven goals to generate the application that is embedded with Open Liberty. 527 | 528 | Next, run the Maven `package` goal: 529 | 530 | include::{common-includes}/os-tabs.adoc[] 531 | 532 | [.tab_content.windows_section] 533 | -- 534 | [role='command'] 535 | ``` 536 | mvnw.cmd package 537 | ``` 538 | -- 539 | 540 | [.tab_content.mac_section] 541 | -- 542 | [role='command'] 543 | ``` 544 | ./mvnw package 545 | ``` 546 | -- 547 | 548 | [.tab_content.linux_section] 549 | -- 550 | [role='command'] 551 | ``` 552 | ./mvnw package 553 | ``` 554 | -- 555 | 556 | Run the repackaged Spring Boot application. This JAR file was defined previously in the [hotspot file=0]`pom.xml` file. 557 | 558 | [role='command'] 559 | ``` 560 | java -jar target/GSSpringBootApp.jar 561 | ``` 562 | 563 | After you see the following message, your Liberty instance is ready: 564 | 565 | [role="no_copy"] 566 | ---- 567 | The defaultServer server is ready to run a smarter planet. 568 | ---- 569 | 570 | // Static guide instruction 571 | ifndef::cloud-hosted[] 572 | Go to the http://localhost:9080/hello[^] URL to access the application. 573 | endif::[] 574 | 575 | // Cloud hosted guide instruction 576 | ifdef::cloud-hosted[] 577 | In another command-line sesssion, run the following command to access the application: 578 | ```bash 579 | curl http://localhost:9080/hello 580 | ``` 581 | endif::[] 582 | 583 | When you need to stop the application, press `CTRL+C`. 584 | 585 | 586 | == Great work! You're done! 587 | 588 | You just ran a basic Spring Boot application with Open Liberty. 589 | 590 | include::{common-includes}/attribution.adoc[subs="attributes"] 591 | -------------------------------------------------------------------------------- /finish/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenLiberty/guide-spring-boot/aa3717cc4f53c112fec831f0eeb68cbc6556f8f9/finish/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /finish/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 3 | -------------------------------------------------------------------------------- /finish/Dockerfile: -------------------------------------------------------------------------------- 1 | # Stage and thin the application 2 | # tag::OLimage1[] 3 | FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal AS staging 4 | # end::OLimage1[] 5 | 6 | # tag::copyJar[] 7 | COPY --chown=1001:0 target/guide-spring-boot-0.1.0.jar \ 8 | /staging/fat-guide-spring-boot-0.1.0.jar 9 | # end::copyJar[] 10 | 11 | # tag::springBootUtility[] 12 | RUN springBootUtility thin \ 13 | --sourceAppPath=/staging/fat-guide-spring-boot-0.1.0.jar \ 14 | --targetThinAppPath=/staging/thin-guide-spring-boot-0.1.0.jar \ 15 | --targetLibCachePath=/staging/lib.index.cache 16 | # end::springBootUtility[] 17 | 18 | # Build the image 19 | # tag::OLimage2[] 20 | FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal 21 | # end::OLimage2[] 22 | 23 | ARG VERSION=1.0 24 | ARG REVISION=SNAPSHOT 25 | 26 | LABEL \ 27 | org.opencontainers.image.authors="Your Name" \ 28 | org.opencontainers.image.vendor="Open Liberty" \ 29 | org.opencontainers.image.url="local" \ 30 | org.opencontainers.image.source="https://github.com/OpenLiberty/guide-spring-boot" \ 31 | org.opencontainers.image.version="$VERSION" \ 32 | org.opencontainers.image.revision="$REVISION" \ 33 | vendor="Open Liberty" \ 34 | name="hello app" \ 35 | version="$VERSION-$REVISION" \ 36 | summary="The hello application from the Spring Boot guide" \ 37 | description="This image contains the hello application running with the Open Liberty runtime." 38 | 39 | # tag::serverXml[] 40 | RUN cp /opt/ol/wlp/templates/servers/springBoot3/server.xml /config/server.xml 41 | # end::serverXml[] 42 | 43 | RUN features.sh 44 | 45 | # tag::libcache[] 46 | COPY --chown=1001:0 --from=staging /staging/lib.index.cache /lib.index.cache 47 | # end::libcache[] 48 | # tag::thinjar[] 49 | COPY --chown=1001:0 --from=staging /staging/thin-guide-spring-boot-0.1.0.jar \ 50 | /config/dropins/spring/thin-guide-spring-boot-0.1.0.jar 51 | # end::thinjar[] 52 | 53 | RUN configure.sh 54 | -------------------------------------------------------------------------------- /finish/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.1.1 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | # e.g. to debug Maven itself, use 32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | # ---------------------------------------------------------------------------- 35 | 36 | if [ -z "$MAVEN_SKIP_RC" ] ; then 37 | 38 | if [ -f /usr/local/etc/mavenrc ] ; then 39 | . /usr/local/etc/mavenrc 40 | fi 41 | 42 | if [ -f /etc/mavenrc ] ; then 43 | . /etc/mavenrc 44 | fi 45 | 46 | if [ -f "$HOME/.mavenrc" ] ; then 47 | . "$HOME/.mavenrc" 48 | fi 49 | 50 | fi 51 | 52 | # OS specific support. $var _must_ be set to either true or false. 53 | cygwin=false; 54 | darwin=false; 55 | mingw=false 56 | case "`uname`" in 57 | CYGWIN*) cygwin=true ;; 58 | MINGW*) mingw=true;; 59 | Darwin*) darwin=true 60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 62 | if [ -z "$JAVA_HOME" ]; then 63 | if [ -x "/usr/libexec/java_home" ]; then 64 | JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME 65 | else 66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 67 | fi 68 | fi 69 | ;; 70 | esac 71 | 72 | if [ -z "$JAVA_HOME" ] ; then 73 | if [ -r /etc/gentoo-release ] ; then 74 | JAVA_HOME=`java-config --jre-home` 75 | fi 76 | fi 77 | 78 | # For Cygwin, ensure paths are in UNIX format before anything is touched 79 | if $cygwin ; then 80 | [ -n "$JAVA_HOME" ] && 81 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 82 | [ -n "$CLASSPATH" ] && 83 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 84 | fi 85 | 86 | # For Mingw, ensure paths are in UNIX format before anything is touched 87 | if $mingw ; then 88 | [ -n "$JAVA_HOME" ] && 89 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 90 | fi 91 | 92 | if [ -z "$JAVA_HOME" ]; then 93 | javaExecutable="`which javac`" 94 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 95 | # readlink(1) is not available as standard on Solaris 10. 96 | readLink=`which readlink` 97 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 98 | if $darwin ; then 99 | javaHome="`dirname \"$javaExecutable\"`" 100 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 101 | else 102 | javaExecutable="`readlink -f \"$javaExecutable\"`" 103 | fi 104 | javaHome="`dirname \"$javaExecutable\"`" 105 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 106 | JAVA_HOME="$javaHome" 107 | export JAVA_HOME 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$JAVACMD" ] ; then 113 | if [ -n "$JAVA_HOME" ] ; then 114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 115 | # IBM's JDK on AIX uses strange locations for the executables 116 | JAVACMD="$JAVA_HOME/jre/sh/java" 117 | else 118 | JAVACMD="$JAVA_HOME/bin/java" 119 | fi 120 | else 121 | JAVACMD="`\\unset -f command; \\command -v java`" 122 | fi 123 | fi 124 | 125 | if [ ! -x "$JAVACMD" ] ; then 126 | echo "Error: JAVA_HOME is not defined correctly." >&2 127 | echo " We cannot execute $JAVACMD" >&2 128 | exit 1 129 | fi 130 | 131 | if [ -z "$JAVA_HOME" ] ; then 132 | echo "Warning: JAVA_HOME environment variable is not set." 133 | fi 134 | 135 | # traverses directory structure from process work directory to filesystem root 136 | # first directory with .mvn subdirectory is considered project base directory 137 | find_maven_basedir() { 138 | if [ -z "$1" ] 139 | then 140 | echo "Path not specified to find_maven_basedir" 141 | return 1 142 | fi 143 | 144 | basedir="$1" 145 | wdir="$1" 146 | while [ "$wdir" != '/' ] ; do 147 | if [ -d "$wdir"/.mvn ] ; then 148 | basedir=$wdir 149 | break 150 | fi 151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 152 | if [ -d "${wdir}" ]; then 153 | wdir=`cd "$wdir/.."; pwd` 154 | fi 155 | # end of workaround 156 | done 157 | printf '%s' "$(cd "$basedir"; pwd)" 158 | } 159 | 160 | # concatenates all lines of a file 161 | concat_lines() { 162 | if [ -f "$1" ]; then 163 | echo "$(tr -s '\n' ' ' < "$1")" 164 | fi 165 | } 166 | 167 | BASE_DIR=$(find_maven_basedir "$(dirname $0)") 168 | if [ -z "$BASE_DIR" ]; then 169 | exit 1; 170 | fi 171 | 172 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR 173 | if [ "$MVNW_VERBOSE" = true ]; then 174 | echo $MAVEN_PROJECTBASEDIR 175 | fi 176 | 177 | ########################################################################################## 178 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 179 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 180 | ########################################################################################## 181 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 182 | if [ "$MVNW_VERBOSE" = true ]; then 183 | echo "Found .mvn/wrapper/maven-wrapper.jar" 184 | fi 185 | else 186 | if [ "$MVNW_VERBOSE" = true ]; then 187 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 188 | fi 189 | if [ -n "$MVNW_REPOURL" ]; then 190 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 191 | else 192 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 193 | fi 194 | while IFS="=" read key value; do 195 | case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; 196 | esac 197 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 198 | if [ "$MVNW_VERBOSE" = true ]; then 199 | echo "Downloading from: $wrapperUrl" 200 | fi 201 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 202 | if $cygwin; then 203 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 204 | fi 205 | 206 | if command -v wget > /dev/null; then 207 | QUIET="--quiet" 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found wget ... using wget" 210 | QUIET="" 211 | fi 212 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 213 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" 214 | else 215 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" 216 | fi 217 | [ $? -eq 0 ] || rm -f "$wrapperJarPath" 218 | elif command -v curl > /dev/null; then 219 | QUIET="--silent" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Found curl ... using curl" 222 | QUIET="" 223 | fi 224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L 226 | else 227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L 228 | fi 229 | [ $? -eq 0 ] || rm -f "$wrapperJarPath" 230 | else 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Falling back to using Java to download" 233 | fi 234 | javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 235 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" 236 | # For Cygwin, switch paths to Windows format before running javac 237 | if $cygwin; then 238 | javaSource=`cygpath --path --windows "$javaSource"` 239 | javaClass=`cygpath --path --windows "$javaClass"` 240 | fi 241 | if [ -e "$javaSource" ]; then 242 | if [ ! -e "$javaClass" ]; then 243 | if [ "$MVNW_VERBOSE" = true ]; then 244 | echo " - Compiling MavenWrapperDownloader.java ..." 245 | fi 246 | # Compiling the Java class 247 | ("$JAVA_HOME/bin/javac" "$javaSource") 248 | fi 249 | if [ -e "$javaClass" ]; then 250 | # Running the downloader 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo " - Running MavenWrapperDownloader.java ..." 253 | fi 254 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 255 | fi 256 | fi 257 | fi 258 | fi 259 | ########################################################################################## 260 | # End of extension 261 | ########################################################################################## 262 | 263 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 264 | 265 | # For Cygwin, switch paths to Windows format before running java 266 | if $cygwin; then 267 | [ -n "$JAVA_HOME" ] && 268 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 269 | [ -n "$CLASSPATH" ] && 270 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 271 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 272 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 273 | fi 274 | 275 | # Provide a "standardized" way to retrieve the CLI args that will 276 | # work with both Windows and non-Windows executions. 277 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 278 | export MAVEN_CMD_LINE_ARGS 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | $MAVEN_DEBUG_OPTS \ 285 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 286 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 287 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 288 | -------------------------------------------------------------------------------- /finish/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Apache Maven Wrapper startup batch script, version 3.1.1 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 30 | @REM e.g. to debug Maven itself, use 31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 33 | @REM ---------------------------------------------------------------------------- 34 | 35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 36 | @echo off 37 | @REM set title of command window 38 | title %0 39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 41 | 42 | @REM set %HOME% to equivalent of $HOME 43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 44 | 45 | @REM Execute a user defined script before this one 46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 50 | :skipRcPre 51 | 52 | @setlocal 53 | 54 | set ERROR_CODE=0 55 | 56 | @REM To isolate internal variables from possible post scripts, we use another setlocal 57 | @setlocal 58 | 59 | @REM ==== START VALIDATION ==== 60 | if not "%JAVA_HOME%" == "" goto OkJHome 61 | 62 | echo. 63 | echo Error: JAVA_HOME not found in your environment. >&2 64 | echo Please set the JAVA_HOME variable in your environment to match the >&2 65 | echo location of your Java installation. >&2 66 | echo. 67 | goto error 68 | 69 | :OkJHome 70 | if exist "%JAVA_HOME%\bin\java.exe" goto init 71 | 72 | echo. 73 | echo Error: JAVA_HOME is set to an invalid directory. >&2 74 | echo JAVA_HOME = "%JAVA_HOME%" >&2 75 | echo Please set the JAVA_HOME variable in your environment to match the >&2 76 | echo location of your Java installation. >&2 77 | echo. 78 | goto error 79 | 80 | @REM ==== END VALIDATION ==== 81 | 82 | :init 83 | 84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 85 | @REM Fallback to current working directory if not found. 86 | 87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 89 | 90 | set EXEC_DIR=%CD% 91 | set WDIR=%EXEC_DIR% 92 | :findBaseDir 93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 94 | cd .. 95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 96 | set WDIR=%CD% 97 | goto findBaseDir 98 | 99 | :baseDirFound 100 | set MAVEN_PROJECTBASEDIR=%WDIR% 101 | cd "%EXEC_DIR%" 102 | goto endDetectBaseDir 103 | 104 | :baseDirNotFound 105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 106 | cd "%EXEC_DIR%" 107 | 108 | :endDetectBaseDir 109 | 110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 111 | 112 | @setlocal EnableExtensions EnableDelayedExpansion 113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 115 | 116 | :endReadAdditionalConfig 117 | 118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 123 | 124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | if "%MVNW_VERBOSE%" == "true" ( 132 | echo Found %WRAPPER_JAR% 133 | ) 134 | ) else ( 135 | if not "%MVNW_REPOURL%" == "" ( 136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 137 | ) 138 | if "%MVNW_VERBOSE%" == "true" ( 139 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 140 | echo Downloading from: %WRAPPER_URL% 141 | ) 142 | 143 | powershell -Command "&{"^ 144 | "$webclient = new-object System.Net.WebClient;"^ 145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 147 | "}"^ 148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ 149 | "}" 150 | if "%MVNW_VERBOSE%" == "true" ( 151 | echo Finished downloading %WRAPPER_JAR% 152 | ) 153 | ) 154 | @REM End of extension 155 | 156 | @REM Provide a "standardized" way to retrieve the CLI args that will 157 | @REM work with both Windows and non-Windows executions. 158 | set MAVEN_CMD_LINE_ARGS=%* 159 | 160 | %MAVEN_JAVA_EXE% ^ 161 | %JVM_CONFIG_MAVEN_PROPS% ^ 162 | %MAVEN_OPTS% ^ 163 | %MAVEN_DEBUG_OPTS% ^ 164 | -classpath %WRAPPER_JAR% ^ 165 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 166 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 167 | if ERRORLEVEL 1 goto error 168 | goto end 169 | 170 | :error 171 | set ERROR_CODE=1 172 | 173 | :end 174 | @endlocal & set ERROR_CODE=%ERROR_CODE% 175 | 176 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 177 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 178 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 179 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 180 | :skipRcPost 181 | 182 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 183 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 184 | 185 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 186 | 187 | cmd /C exit /B %ERROR_CODE% 188 | -------------------------------------------------------------------------------- /finish/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.5.0 9 | 10 | 11 | com.example 12 | guide-spring-boot 13 | 0.1.0 14 | spring-boot-complete 15 | Demo project for Spring Boot 16 | 17 | 18 | 21 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | io.openliberty.tools 50 | liberty-maven-plugin 51 | 3.11.3 52 | 53 | 54 | apps 55 | 56 | 57 | spring-boot-project 58 | 59 | 60 | minify,runnable 61 | 62 | 63 | GSSpringBootApp 64 | 65 | 66 | 67 | 68 | 69 | package-server 70 | package 71 | 72 | create 73 | install-feature 74 | deploy 75 | package 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /finish/src/main/java/com/example/springboot/Application.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.context.annotation.Bean; 10 | 11 | @SpringBootApplication 12 | public class Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(Application.class, args); 16 | } 17 | 18 | @Bean 19 | public CommandLineRunner commandLineRunner(ApplicationContext ctx) { 20 | return args -> { 21 | 22 | System.out.println("Let's inspect the beans provided by Spring Boot:"); 23 | 24 | String[] beanNames = ctx.getBeanDefinitionNames(); 25 | Arrays.sort(beanNames); 26 | for (String beanName : beanNames) { 27 | System.out.println(beanName); 28 | } 29 | 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /finish/src/main/java/com/example/springboot/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HelloController { 8 | 9 | @GetMapping("/hello") 10 | public String index() { 11 | return "Greetings from Spring Boot!"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /finish/src/main/liberty/config/server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jakartaee-10.0 6 | 7 | servlet 8 | 9 | 10 | springBoot-3.0 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /finish/src/main/liberty/instantOn/crac.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | crac-1.4 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /finish/src/test/java/com/example/springboot/HelloControllerIT.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.boot.test.web.client.TestRestTemplate; 8 | import org.springframework.http.ResponseEntity; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 13 | public class HelloControllerIT { 14 | 15 | @Autowired 16 | private TestRestTemplate template; 17 | 18 | @Test 19 | public void getHello() throws Exception { 20 | ResponseEntity response = template.getForEntity("/hello", String.class); 21 | assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /finish/src/test/java/com/example/springboot/HelloControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import static org.hamcrest.Matchers.equalTo; 4 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.test.web.servlet.MockMvc; 14 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 15 | 16 | @SpringBootTest 17 | @AutoConfigureMockMvc 18 | public class HelloControllerTest { 19 | 20 | @Autowired 21 | private MockMvc mvc; 22 | 23 | @Test 24 | public void getHello() throws Exception { 25 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 26 | .andExpect(status().isOk()) 27 | .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /instantOn/Dockerfile: -------------------------------------------------------------------------------- 1 | # Stage and thin the application 2 | # tag::OLimage1[] 3 | FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal AS staging 4 | # end::OLimage1[] 5 | 6 | # tag::copyJar[] 7 | COPY --chown=1001:0 target/guide-spring-boot-0.1.0.jar \ 8 | /staging/fat-guide-spring-boot-0.1.0.jar 9 | # end::copyJar[] 10 | 11 | # tag::springBootUtility[] 12 | RUN springBootUtility thin \ 13 | --sourceAppPath=/staging/fat-guide-spring-boot-0.1.0.jar \ 14 | --targetThinAppPath=/staging/thin-guide-spring-boot-0.1.0.jar \ 15 | --targetLibCachePath=/staging/lib.index.cache 16 | # end::springBootUtility[] 17 | 18 | # Build the image 19 | # tag::OLimage2[] 20 | FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal 21 | # end::OLimage2[] 22 | 23 | ARG VERSION=1.0 24 | ARG REVISION=SNAPSHOT 25 | 26 | LABEL \ 27 | org.opencontainers.image.authors="Your Name" \ 28 | org.opencontainers.image.vendor="Open Liberty" \ 29 | org.opencontainers.image.url="local" \ 30 | org.opencontainers.image.source="https://github.com/OpenLiberty/guide-spring-boot" \ 31 | org.opencontainers.image.version="$VERSION" \ 32 | org.opencontainers.image.revision="$REVISION" \ 33 | vendor="Open Liberty" \ 34 | name="hello app" \ 35 | version="$VERSION-$REVISION" \ 36 | summary="The hello application from the Spring Boot guide" \ 37 | description="This image contains the hello application running with the Open Liberty runtime." 38 | 39 | # tag::serverXml[] 40 | RUN cp /opt/ol/wlp/templates/servers/springBoot3/server.xml /config/server.xml 41 | # end::serverXml[] 42 | 43 | # tag::cracXml[] 44 | COPY --chown=1001:0 src/main/liberty/instantOn/crac.xml \ 45 | /config/configDropins/defaults/crac.xml 46 | # end::cracXml[] 47 | 48 | RUN features.sh 49 | 50 | # tag::libcache[] 51 | COPY --chown=1001:0 --from=staging /staging/lib.index.cache /lib.index.cache 52 | # end::libcache[] 53 | # tag::thinjar[] 54 | COPY --chown=1001:0 --from=staging /staging/thin-guide-spring-boot-0.1.0.jar \ 55 | /config/dropins/spring/thin-guide-spring-boot-0.1.0.jar 56 | # end::thinjar[] 57 | 58 | RUN configure.sh 59 | -------------------------------------------------------------------------------- /scripts/dailyBuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while getopts t:d:b:u:j: flag; do 3 | case "${flag}" in 4 | t) DATE="${OPTARG}" ;; 5 | d) DRIVER="${OPTARG}" ;; 6 | b) BUILD="${OPTARG}" ;; 7 | u) DOCKER_USERNAME="${OPTARG}" ;; 8 | j) JDK_LEVEL="${OPTARG}" ;; 9 | *) echo "Invalid option";; 10 | esac 11 | done 12 | 13 | echo "Testing daily build image" 14 | 15 | if [ "$JDK_LEVEL" == "11" ]; then 16 | echo "Test skipped because the guide does not support Java 11." 17 | exit 0 18 | fi 19 | 20 | if [ "$JDK_LEVEL" == "17" ]; then 21 | echo "Test skipped because the guide does not support Java 17." 22 | exit 0 23 | fi 24 | 25 | sed -i "\#liberty-maven-plugin#,\##cliberty-maven-plugin3.11.3https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/nightly/$DATE/$DRIVER" pom.xml 26 | cat pom.xml 27 | 28 | if [[ "$DOCKER_USERNAME" != "" ]]; then 29 | sed -i "s;FROM icr.io/appcafe/open-liberty:full-java17-openj9-ubi;FROM $DOCKER_USERNAME/olguides:$BUILD-java17;g" Dockerfile 30 | sed -i "s;FROM icr.io/appcafe/open-liberty:kernel-slim-java17-openj9-ubi;FROM $DOCKER_USERNAME/olguides:$BUILD-java17;g" Dockerfile 31 | sed -i "s;RUN features.sh;#RUN features.sh;g" Dockerfile 32 | cat Dockerfile 33 | fi 34 | 35 | sudo -E ../scripts/testApp.sh 36 | -------------------------------------------------------------------------------- /scripts/dockerImageTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while getopts t:d:v: flag; do 3 | case "${flag}" in 4 | t) DATE="${OPTARG}" ;; 5 | d) DRIVER="${OPTARG}" ;; 6 | v) OL_LEVEL="${OPTARG}";; 7 | *) echo "Invalid option";; 8 | esac 9 | done 10 | 11 | echo "Testing latest OpenLiberty Docker image" 12 | 13 | sed -i "\#liberty-maven-plugin#,\##cliberty-maven-plugin3.8.2https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/nightly/""$DATE""/""$DRIVER""" pom.xml 14 | cat pom.xml 15 | 16 | if [[ "$OL_LEVEL" != "" ]]; then 17 | sed -i "s;FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal;FROM cp.stg.icr.io/cp/olc/open-liberty-vnext:$OL_LEVEL-full-java21-openj9-ubi-minimal;g" Dockerfile 18 | sed -i "s;FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal;FROM cp.stg.icr.io/cp/olc/open-liberty-vnext:$OL_LEVEL-full-java21-openj9-ubi-minimal;g" Dockerfile 19 | else 20 | sed -i "s;FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal;FROM cp.stg.icr.io/cp/olc/open-liberty-daily:full-java21-openj9-ubi-minimal;g" Dockerfile 21 | sed -i "s;FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal;FROM cp.stg.icr.io/cp/olc/open-liberty-daily:full-java21-openj9-ubi-minimal;g" Dockerfile 22 | fi 23 | sed -i "s;RUN features.sh;#RUN features.sh;g" Dockerfile 24 | cat Dockerfile 25 | 26 | echo "$DOCKER_PASSWORD" | sudo docker login -u "$DOCKER_USERNAME" --password-stdin cp.stg.icr.io 27 | if [[ "$OL_LEVEL" != "" ]]; then 28 | sudo docker pull -q "cp.stg.icr.io/cp/olc/open-liberty-vnext:$OL_LEVEL-full-java21-openj9-ubi-minimal" 29 | sudo echo "build level:"; docker inspect --format "{{ index .Config.Labels \"org.opencontainers.image.revision\"}}" cp.stg.icr.io/cp/olc/open-liberty-vnext:$OL_LEVEL-full-java21-openj9-ubi-minimal 30 | else 31 | sudo docker pull -q "cp.stg.icr.io/cp/olc/open-liberty-daily:full-java21-openj9-ubi-minimal" 32 | sudo echo "build level:"; docker inspect --format "{{ index .Config.Labels \"org.opencontainers.image.revision\"}}" cp.stg.icr.io/cp/olc/open-liberty-daily:full-java21-openj9-ubi-minimal 33 | fi 34 | 35 | sudo -E ../scripts/testApp.sh 36 | -------------------------------------------------------------------------------- /scripts/testApp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euxo pipefail 3 | 4 | ############################################################################## 5 | ## 6 | ## GH actions CI test script 7 | ## 8 | ############################################################################## 9 | 10 | ./mvnw -version 11 | 12 | ./mvnw -ntp -Dhttp.keepAlive=false \ 13 | -Dmaven.wagon.http.pool=false \ 14 | -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 \ 15 | -q clean package 16 | 17 | docker pull -q icr.io/appcafe/open-liberty:kernel-slim-java17-openj9-ubi 18 | 19 | docker build -t springboot . 20 | docker run -d --name springBootContainer --rm -p 9080:9080 -p 9443:9443 springboot 21 | 22 | sleep 40 23 | 24 | status="$(curl --write-out "%{http_code}\n" --silent --output /dev/null "http://localhost:9080/hello")" 25 | if [ "$status" == "200" ]; then 26 | echo ENDPOINT OK 27 | else 28 | echo "$status" 29 | echo ENDPOINT NOT OK 30 | docker exec springBootContainer cat /logs/messages.log 31 | docker stop springBootContainer 32 | exit 1 33 | fi 34 | 35 | docker exec springBootContainer cat /logs/messages.log | grep product 36 | docker exec springBootContainer cat /logs/messages.log | grep java 37 | 38 | docker stop springBootContainer 39 | 40 | uname -r 41 | cp ../instantOn/Dockerfile Dockerfile 42 | docker run --name springBootCheckpointContainer --privileged --env WLP_CHECKPOINT=afterAppStart springboot 43 | docker commit springBootCheckpointContainer springboot-instanton 44 | docker rm springBootCheckpointContainer 45 | docker images 46 | docker run --rm -d \ 47 | --name springBootContainer \ 48 | --cap-add=CHECKPOINT_RESTORE \ 49 | --cap-add=SETPCAP \ 50 | --security-opt seccomp=unconfined \ 51 | -p 9080:9080 \ 52 | springboot-instanton 53 | sleep 10 54 | docker logs springBootContainer 55 | status="$(curl --write-out "%{http_code}\n" --silent --output /dev/null "http://localhost:9080/hello")" 56 | docker stop springBootContainer 57 | if [ "$status" == "200" ]; then 58 | echo ENDPOINT OK 59 | else 60 | echo "$status" 61 | echo ENDPOINT NOT OK 62 | exit 1 63 | fi 64 | 65 | ./mvnw -ntp liberty:start 66 | status="$(curl --write-out "%{http_code}\n" --silent --output /dev/null "http://localhost:9080/hello")" 67 | if [ "$status" == "200" ]; then 68 | echo ENDPOINT OK 69 | else 70 | echo "$status" 71 | echo ENDPOINT NOT OK 72 | ./mvnw -ntp liberty:stop 73 | exit 1 74 | fi 75 | ./mvnw -ntp liberty:stop 76 | 77 | if [ ! -f "target/GSSpringBootApp.jar" ]; then 78 | echo "target/GSSpringBootApp.jar was not generated!" 79 | exit 1 80 | fi 81 | 82 | $JAVA_HOME/bin/java -jar target/GSSpringBootApp.jar & 83 | GSSBA_PID=$! 84 | echo "GSSBA_PID=$GSSBA_PID" 85 | sleep 30 86 | status="$(curl --write-out "%{http_code}\n" --silent --output /dev/null "http://localhost:9080/hello")" 87 | kill $GSSBA_PID 88 | if [ "$status" == "200" ]; then 89 | echo ENDPOINT OK 90 | else 91 | echo "$status" 92 | echo ENDPOINT NOT OK 93 | exit 1 94 | fi 95 | -------------------------------------------------------------------------------- /start/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenLiberty/guide-spring-boot/aa3717cc4f53c112fec831f0eeb68cbc6556f8f9/start/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /start/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar 3 | -------------------------------------------------------------------------------- /start/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.1.1 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | # e.g. to debug Maven itself, use 32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | # ---------------------------------------------------------------------------- 35 | 36 | if [ -z "$MAVEN_SKIP_RC" ] ; then 37 | 38 | if [ -f /usr/local/etc/mavenrc ] ; then 39 | . /usr/local/etc/mavenrc 40 | fi 41 | 42 | if [ -f /etc/mavenrc ] ; then 43 | . /etc/mavenrc 44 | fi 45 | 46 | if [ -f "$HOME/.mavenrc" ] ; then 47 | . "$HOME/.mavenrc" 48 | fi 49 | 50 | fi 51 | 52 | # OS specific support. $var _must_ be set to either true or false. 53 | cygwin=false; 54 | darwin=false; 55 | mingw=false 56 | case "`uname`" in 57 | CYGWIN*) cygwin=true ;; 58 | MINGW*) mingw=true;; 59 | Darwin*) darwin=true 60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 62 | if [ -z "$JAVA_HOME" ]; then 63 | if [ -x "/usr/libexec/java_home" ]; then 64 | JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME 65 | else 66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME 67 | fi 68 | fi 69 | ;; 70 | esac 71 | 72 | if [ -z "$JAVA_HOME" ] ; then 73 | if [ -r /etc/gentoo-release ] ; then 74 | JAVA_HOME=`java-config --jre-home` 75 | fi 76 | fi 77 | 78 | # For Cygwin, ensure paths are in UNIX format before anything is touched 79 | if $cygwin ; then 80 | [ -n "$JAVA_HOME" ] && 81 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 82 | [ -n "$CLASSPATH" ] && 83 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 84 | fi 85 | 86 | # For Mingw, ensure paths are in UNIX format before anything is touched 87 | if $mingw ; then 88 | [ -n "$JAVA_HOME" ] && 89 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 90 | fi 91 | 92 | if [ -z "$JAVA_HOME" ]; then 93 | javaExecutable="`which javac`" 94 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 95 | # readlink(1) is not available as standard on Solaris 10. 96 | readLink=`which readlink` 97 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 98 | if $darwin ; then 99 | javaHome="`dirname \"$javaExecutable\"`" 100 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 101 | else 102 | javaExecutable="`readlink -f \"$javaExecutable\"`" 103 | fi 104 | javaHome="`dirname \"$javaExecutable\"`" 105 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 106 | JAVA_HOME="$javaHome" 107 | export JAVA_HOME 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$JAVACMD" ] ; then 113 | if [ -n "$JAVA_HOME" ] ; then 114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 115 | # IBM's JDK on AIX uses strange locations for the executables 116 | JAVACMD="$JAVA_HOME/jre/sh/java" 117 | else 118 | JAVACMD="$JAVA_HOME/bin/java" 119 | fi 120 | else 121 | JAVACMD="`\\unset -f command; \\command -v java`" 122 | fi 123 | fi 124 | 125 | if [ ! -x "$JAVACMD" ] ; then 126 | echo "Error: JAVA_HOME is not defined correctly." >&2 127 | echo " We cannot execute $JAVACMD" >&2 128 | exit 1 129 | fi 130 | 131 | if [ -z "$JAVA_HOME" ] ; then 132 | echo "Warning: JAVA_HOME environment variable is not set." 133 | fi 134 | 135 | # traverses directory structure from process work directory to filesystem root 136 | # first directory with .mvn subdirectory is considered project base directory 137 | find_maven_basedir() { 138 | if [ -z "$1" ] 139 | then 140 | echo "Path not specified to find_maven_basedir" 141 | return 1 142 | fi 143 | 144 | basedir="$1" 145 | wdir="$1" 146 | while [ "$wdir" != '/' ] ; do 147 | if [ -d "$wdir"/.mvn ] ; then 148 | basedir=$wdir 149 | break 150 | fi 151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 152 | if [ -d "${wdir}" ]; then 153 | wdir=`cd "$wdir/.."; pwd` 154 | fi 155 | # end of workaround 156 | done 157 | printf '%s' "$(cd "$basedir"; pwd)" 158 | } 159 | 160 | # concatenates all lines of a file 161 | concat_lines() { 162 | if [ -f "$1" ]; then 163 | echo "$(tr -s '\n' ' ' < "$1")" 164 | fi 165 | } 166 | 167 | BASE_DIR=$(find_maven_basedir "$(dirname $0)") 168 | if [ -z "$BASE_DIR" ]; then 169 | exit 1; 170 | fi 171 | 172 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR 173 | if [ "$MVNW_VERBOSE" = true ]; then 174 | echo $MAVEN_PROJECTBASEDIR 175 | fi 176 | 177 | ########################################################################################## 178 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 179 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 180 | ########################################################################################## 181 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 182 | if [ "$MVNW_VERBOSE" = true ]; then 183 | echo "Found .mvn/wrapper/maven-wrapper.jar" 184 | fi 185 | else 186 | if [ "$MVNW_VERBOSE" = true ]; then 187 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 188 | fi 189 | if [ -n "$MVNW_REPOURL" ]; then 190 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 191 | else 192 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 193 | fi 194 | while IFS="=" read key value; do 195 | case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; 196 | esac 197 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 198 | if [ "$MVNW_VERBOSE" = true ]; then 199 | echo "Downloading from: $wrapperUrl" 200 | fi 201 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 202 | if $cygwin; then 203 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 204 | fi 205 | 206 | if command -v wget > /dev/null; then 207 | QUIET="--quiet" 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found wget ... using wget" 210 | QUIET="" 211 | fi 212 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 213 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" 214 | else 215 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" 216 | fi 217 | [ $? -eq 0 ] || rm -f "$wrapperJarPath" 218 | elif command -v curl > /dev/null; then 219 | QUIET="--silent" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Found curl ... using curl" 222 | QUIET="" 223 | fi 224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L 226 | else 227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L 228 | fi 229 | [ $? -eq 0 ] || rm -f "$wrapperJarPath" 230 | else 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Falling back to using Java to download" 233 | fi 234 | javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 235 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" 236 | # For Cygwin, switch paths to Windows format before running javac 237 | if $cygwin; then 238 | javaSource=`cygpath --path --windows "$javaSource"` 239 | javaClass=`cygpath --path --windows "$javaClass"` 240 | fi 241 | if [ -e "$javaSource" ]; then 242 | if [ ! -e "$javaClass" ]; then 243 | if [ "$MVNW_VERBOSE" = true ]; then 244 | echo " - Compiling MavenWrapperDownloader.java ..." 245 | fi 246 | # Compiling the Java class 247 | ("$JAVA_HOME/bin/javac" "$javaSource") 248 | fi 249 | if [ -e "$javaClass" ]; then 250 | # Running the downloader 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo " - Running MavenWrapperDownloader.java ..." 253 | fi 254 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 255 | fi 256 | fi 257 | fi 258 | fi 259 | ########################################################################################## 260 | # End of extension 261 | ########################################################################################## 262 | 263 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 264 | 265 | # For Cygwin, switch paths to Windows format before running java 266 | if $cygwin; then 267 | [ -n "$JAVA_HOME" ] && 268 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 269 | [ -n "$CLASSPATH" ] && 270 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 271 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 272 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 273 | fi 274 | 275 | # Provide a "standardized" way to retrieve the CLI args that will 276 | # work with both Windows and non-Windows executions. 277 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 278 | export MAVEN_CMD_LINE_ARGS 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | $MAVEN_DEBUG_OPTS \ 285 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 286 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 287 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 288 | -------------------------------------------------------------------------------- /start/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Apache Maven Wrapper startup batch script, version 3.1.1 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 30 | @REM e.g. to debug Maven itself, use 31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 33 | @REM ---------------------------------------------------------------------------- 34 | 35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 36 | @echo off 37 | @REM set title of command window 38 | title %0 39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 41 | 42 | @REM set %HOME% to equivalent of $HOME 43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 44 | 45 | @REM Execute a user defined script before this one 46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 50 | :skipRcPre 51 | 52 | @setlocal 53 | 54 | set ERROR_CODE=0 55 | 56 | @REM To isolate internal variables from possible post scripts, we use another setlocal 57 | @setlocal 58 | 59 | @REM ==== START VALIDATION ==== 60 | if not "%JAVA_HOME%" == "" goto OkJHome 61 | 62 | echo. 63 | echo Error: JAVA_HOME not found in your environment. >&2 64 | echo Please set the JAVA_HOME variable in your environment to match the >&2 65 | echo location of your Java installation. >&2 66 | echo. 67 | goto error 68 | 69 | :OkJHome 70 | if exist "%JAVA_HOME%\bin\java.exe" goto init 71 | 72 | echo. 73 | echo Error: JAVA_HOME is set to an invalid directory. >&2 74 | echo JAVA_HOME = "%JAVA_HOME%" >&2 75 | echo Please set the JAVA_HOME variable in your environment to match the >&2 76 | echo location of your Java installation. >&2 77 | echo. 78 | goto error 79 | 80 | @REM ==== END VALIDATION ==== 81 | 82 | :init 83 | 84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 85 | @REM Fallback to current working directory if not found. 86 | 87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 89 | 90 | set EXEC_DIR=%CD% 91 | set WDIR=%EXEC_DIR% 92 | :findBaseDir 93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 94 | cd .. 95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 96 | set WDIR=%CD% 97 | goto findBaseDir 98 | 99 | :baseDirFound 100 | set MAVEN_PROJECTBASEDIR=%WDIR% 101 | cd "%EXEC_DIR%" 102 | goto endDetectBaseDir 103 | 104 | :baseDirNotFound 105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 106 | cd "%EXEC_DIR%" 107 | 108 | :endDetectBaseDir 109 | 110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 111 | 112 | @setlocal EnableExtensions EnableDelayedExpansion 113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 115 | 116 | :endReadAdditionalConfig 117 | 118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 123 | 124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | if "%MVNW_VERBOSE%" == "true" ( 132 | echo Found %WRAPPER_JAR% 133 | ) 134 | ) else ( 135 | if not "%MVNW_REPOURL%" == "" ( 136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" 137 | ) 138 | if "%MVNW_VERBOSE%" == "true" ( 139 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 140 | echo Downloading from: %WRAPPER_URL% 141 | ) 142 | 143 | powershell -Command "&{"^ 144 | "$webclient = new-object System.Net.WebClient;"^ 145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 147 | "}"^ 148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ 149 | "}" 150 | if "%MVNW_VERBOSE%" == "true" ( 151 | echo Finished downloading %WRAPPER_JAR% 152 | ) 153 | ) 154 | @REM End of extension 155 | 156 | @REM Provide a "standardized" way to retrieve the CLI args that will 157 | @REM work with both Windows and non-Windows executions. 158 | set MAVEN_CMD_LINE_ARGS=%* 159 | 160 | %MAVEN_JAVA_EXE% ^ 161 | %JVM_CONFIG_MAVEN_PROPS% ^ 162 | %MAVEN_OPTS% ^ 163 | %MAVEN_DEBUG_OPTS% ^ 164 | -classpath %WRAPPER_JAR% ^ 165 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 166 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 167 | if ERRORLEVEL 1 goto error 168 | goto end 169 | 170 | :error 171 | set ERROR_CODE=1 172 | 173 | :end 174 | @endlocal & set ERROR_CODE=%ERROR_CODE% 175 | 176 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 177 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 178 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 179 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 180 | :skipRcPost 181 | 182 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 183 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 184 | 185 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 186 | 187 | cmd /C exit /B %ERROR_CODE% 188 | -------------------------------------------------------------------------------- /start/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.5.0 9 | 10 | 11 | com.example 12 | guide-spring-boot 13 | 0.1.0 14 | spring-boot-complete 15 | Demo project for Spring Boot 16 | 17 | 18 | 21 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /start/src/main/java/com/example/springboot/Application.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.context.annotation.Bean; 10 | 11 | @SpringBootApplication 12 | public class Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(Application.class, args); 16 | } 17 | 18 | @Bean 19 | public CommandLineRunner commandLineRunner(ApplicationContext ctx) { 20 | return args -> { 21 | 22 | System.out.println("Let's inspect the beans provided by Spring Boot:"); 23 | 24 | String[] beanNames = ctx.getBeanDefinitionNames(); 25 | Arrays.sort(beanNames); 26 | for (String beanName : beanNames) { 27 | System.out.println(beanName); 28 | } 29 | 30 | }; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /start/src/main/java/com/example/springboot/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HelloController { 8 | 9 | @GetMapping("/hello") 10 | public String index() { 11 | return "Greetings from Spring Boot!"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /start/src/main/liberty/config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenLiberty/guide-spring-boot/aa3717cc4f53c112fec831f0eeb68cbc6556f8f9/start/src/main/liberty/config/.gitkeep -------------------------------------------------------------------------------- /start/src/main/liberty/instantOn/crac.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | crac-1.4 6 | 7 | 8 | -------------------------------------------------------------------------------- /start/src/test/java/com/example/springboot/HelloControllerIT.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.boot.test.web.client.TestRestTemplate; 8 | import org.springframework.http.ResponseEntity; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 13 | public class HelloControllerIT { 14 | 15 | @Autowired 16 | private TestRestTemplate template; 17 | 18 | @Test 19 | public void getHello() throws Exception { 20 | ResponseEntity response = template.getForEntity("/hello", String.class); 21 | assertThat(response.getBody()).isEqualTo("Greetings from Spring Boot!"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /start/src/test/java/com/example/springboot/HelloControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.example.springboot; 2 | 3 | import static org.hamcrest.Matchers.equalTo; 4 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.test.web.servlet.MockMvc; 14 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 15 | 16 | @SpringBootTest 17 | @AutoConfigureMockMvc 18 | public class HelloControllerTest { 19 | 20 | @Autowired 21 | private MockMvc mvc; 22 | 23 | @Test 24 | public void getHello() throws Exception { 25 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 26 | .andExpect(status().isOk()) 27 | .andExpect(content().string(equalTo("Greetings from Spring Boot!"))); 28 | } 29 | } 30 | --------------------------------------------------------------------------------