In this sample application, you will create a basic Java web application using Quarkus. This provides a starting point for creating Java microservice applications running as a native application on GraalVM. It contains application code with a simple /hello endpoint, a swagger UI and a health check at /health.
You can deploy this application to IBM Cloud or build it locally by cloning this repo first. Once your app is live, you can access the /hello endpoint to build out your cloud native application.
After you have created a new git repo from this git template, remember to rename the project.
Edit the pom.xml and change the artifactId from the default name to the name you used to create the template.
Make sure you are logged into the IBM Cloud using the IBM Cloud CLI and have access to you development cluster. If you are using OpenShift make sure you have logged into the OpenShift CLI on the command line.
Install the IBM Garage for Cloud CLI.
npm i -g @garage-catalyst/ibm-garage-cloud-cli
Use the IBM Garage for Cloud CLI to register the GIT Repo
igc pipeline -n dev --tekton --pipeline ibm-java-maven
See the Deploy an app guide in the IBM Cloud-Native toolkit for details.
To get started building this application locally you need to install
- Maven
- JDK 11+
Use the following command to build and run an application:
./mvnw quarkus:dev
For more details on how to use this Starter Kit Template please review the IBM Garage for Cloud Cloud-Native Toolkit Guide
This Starter Kit Template is based on Quarkus Bootstrapping the project.
It was bootstrapped with the command:
mvn io.quarkus:quarkus-maven-plugin:1.12.0.Final:create \
-DprojectGroupId=com.ibm \
-DprojectArtifactId=template-quarkus \
-DclassName="com.ibm.GreetingResource" \
-Dpath="/hello" \
-Dextensions="smallrye-openapi, quarkus-resteasy-jsonb, quarkus-smallrye-opentracing"
OpenTracing support was added automatically with extensions="quarkus-smallrye-opentracing" above.
Added properties to src/main/resources/application.properties file to configure tracing.
quarkus.jaeger.service-namedefine the name of the service tracing is collected for. Update this name for your service.quarkus.jaeger.sampler-typeuse a constant sampling strategy.quarkus.jaeger.sampler-paramsample all requestsquarkus.log.console.formatadd trace IDs to the log messages.
These properties can be set via environment variables instead.
Added Logger to GreetingResource.java to illustrate log messages with trace IDs.
OpenAPI and Swagger support was added automatically with the extensions="smallrye-openapi" above.
- Once your application is started, you can make a request to the
/q/openapiendpoint to get the API Documentation. - The Swagger UI can be located at
/q/swagger-ui - For more information on OpenAPI and Swagger support click here
To add support for the Cloud-Native Toolkit CI/CD pipelines
- the
Dockerfile was added based on this guide. - The
.dockerignorefile was updated to remove the*line.
# *
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
- The helm charts in the
chartfolder were added.
Create the /health health check endpoint
- Add the
/healthhealth check endpoint with thesrc/main/java/com/ibm/HealthResource.javafile. - Add the health check test with the
src/test/java/com/ibm/HealthResourceTest.javafile.
Support for running the SonarQube CLI was added.
-
The
sonar-project.propertiesfile was added. The values in this file should be updated to match your project. -
The
pom.xmlfile was modified to enable code coverage using JaCoCo based on this guide. Changes to the file are:- Add
jacoco.versionproperty
<properties> ... <jacoco.version>0.8.6</jacoco.version> </properties>- Add the
jacoco-maven-pluginplugin
</plugins> .... <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>default-report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/jacoco.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> - Add
- Learn more about Quarkus.
- Explore other sample applications on IBM Cloud.
This sample application is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.