- Helidon MP Quick Start
This quick start describes how to create and run a basic Helidon MP application and optionally, how to build a Docker image and use Kubernetes to deploy it.
Generate the Project
The Helidon Project Starter allows you to quickly generate a project with basic functionality that lets you explore the features of Helidon and that’s also customizable enough to use as a starting point for your own projects and applications.
- Make sure your environment is properly set up for Helidon development. See Getting Started.
- Go to the Helidon Project Starter page on the Helidon website.
- Under Helidon Flavor, select Helidon MP and click Next.
- Under Application Type, select Quickstart and click Next.
- Under Media Support, select a JSON library and click Next.
- Under Customize Project, leave the values set to their default values since this is a tutorial. If you were planning on using this project as a base for a real application, you would update the values accordingly.
- Click Download to save the project zip archive to your computer. This is the Maven project that’s the basis for your Helidon Quick Start application.
You can also generate the Quick Start project using the Helidon CLI. Run the following command to create a Maven project in your current directory: helidon init --batch -Dflavor=mp -Dapp-type=quickstart
Now that you’ve generated the project, you can build a Helidon application and start experimenting.
- Extract the project files and navigate to the expanded directory. It should include a Maven project file, Helidon project metadata, the application’s source code, and various other development files.
- Build the application by running
mvn package. The project builds an application jar and saves all runtime dependencies in thetarget/libsdirectory, making it easy to start the application. - Start the application by running
java -jar target/myproject.jar. The name of your application .jar file matches theartifactIdspecified when you built the Project Starter. If you changed the defaultartifactId, make sure you update the .jar file name in the command accordingly.
The example application generated by the Project Starter is a simple "Hello, World!" greeting service. It supports GET requests for generating a greeting message, and a PUT request for changing the greeting itself. The response is encoded using JSON. For example:
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}
curl -X GET http://localhost:8080/greet/Joe
{"message":"Hello Joe!"}
curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Hola"}' http://localhost:8080/greet/greeting
curl -X GET http://localhost:8080/greet/Jose
{"message":"Hola Jose!"}Congratulations! You now have a working Helidon MP application. You can use it to:
Experiment with Helidon MP features and services
Try out the Health service and the Metrics service
and much more!
Track Health and Metrics
Helidon provides built-in support for monitoring the Health and Metrics endpoints in your application.
Use the Health component to monitor the health of your microservice to make sure it is available and performing correctly. For more information on how to retrieve and monitor Health data about your application, see Health.
curl -s -X GET http://localhost:8080/healthUse the Metrics component to export telemetry to management agents and to register and update metrics to expose telemetry data from their services. For more information on how to generate and send Metrics data from your application, see Metrics.
curl -s -X GET http://localhost:8080/metricscurl -H 'Accept: application/json' -X GET http://localhost:8080/metricsBuild a Docker Image
The project includes a Dockerfile so that you can easily build and run a Docker image.
To build the Docker image, you must have Docker installed and running on your system.
- Build the Docker image by running
docker build -t myproject .. - Run the Docker image by running
docker run --rm -p 8080:8080 myproject:latest. - As you did earlier, you can test the
"Hello, World!"application as a Docker image using GET and PUT requests. For example,
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}
curl -X GET http://localhost:8080/greet/Joe
{"message":"Hello Joe!"}
curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Hola"}' http://localhost:8080/greet/greeting
curl -X GET http://localhost:8080/greet/Jose
{"message":"Hola Jose!"}Deploy Application to Kubernetes
To deploy the application to Kubernetes, you must have access to a Kubernetes cluster. Some lightweight options for running Kubernetes include Docker Desktop or minikube. This quick start assumes you’re using Docker Desktop. See Docker Desktop in the Docker documentation.
If you haven’t already, install kubectl, the Kubernetes command line tool. See Install kubectl in the Kubernetes documentation.
- Set up a Kubernetes cluster.
- Verify that you can connect to the cluster by running
kubectl cluster-infoand then runningkubectl get nodes. - Navigate to the Quick Start project folder,
myproject/. - Deploy the application to Kubernetes by running
kubectl create -f app.yamland thenkubectl get pods. Wait for the quick start pod to beRUNNING.This will create a service that is exposed to any node port.
- Look up the new service to find the port by running
kubectl get service myproject.Make a note of the port numbers. If you want to access the Health and Metrics endpoints, make sure you use the NodePort number (the second port number) instead of
8080. For example,curl -X GET http://localhost:31431/greet.
To remove the application from Kubernetes, run kubectl delete -f app.yaml.
Build GraalVM Native and Custom Java Runtime Images
Helidon also includes support for GraalVM Native Images and custom Java Runtime Images. For more information, see:
Next Steps
Learn more about Helidon MP: