Piranha - a modern cloud runtime

This project is maintained by piranhacloud

Create a Hello World web application

If you are looking to create a simple Hello World web application with Piranha Server to get started then look no further!

In 5 steps you will learn how to create the web application. They are:

  1. Create the Maven POM file
  2. Add the helloworld.html page
  3. Add an integration test
  4. Test the application
  5. Deploy the application

Create the Maven POM file

Create an empty directory to store your Maven project. Inside of that directory create the pom.xml file with the content as below.

<?xml version="1.0" encoding="UTF-8"?>

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <name>HelloWorld webapplication</name>

Add the Hello World HTML file

Add the helloworld.html file in the src/main/webapp directory.

<!DOCTYPE html>

        <title>Hello World</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <div>Hello World!</div>

Add an integration test

As we want to make sure the application gets tested before we release an integration test is added which will be executed as part of the build.

We’ll add the integration test to the src/test/java directory.

package helloworld;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

class HelloWorldIT {
    void testHelloWorldHtml() throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest
                .newBuilder(new URI("http://localhost:8080/helloworld/helloworld.html"))
        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
        assertTrue(response.body().contains("Hello World!"));

Test the application

The application is setup to use JUnit to do integration testing using the Piranha Maven plugin so when you are building the application it will also execute an integration test validating the web application works.

To build and test the application execute the following command:

  mvn install

Deploy the application

To deploy your application you will need 2 pieces.

  1. The Piranha Server distribution zip.
  2. The WAR file you just produced.

For the Piranha Servlet distribution zip go to Maven Central.

For the WAR file see the target directory.

Once you have downloaded the Piranha Server distribution zip extract it into an empty directory and then copy the WAR file in the webapps directory.

From the bin directory of Piranha Server start the server using the command line below:



As you can see getting started with Piranha Server is straightforward!


  1. ZIP file containing sources