---
title: "How to Create an HTML Server with Vert.x and Groovy: A Step by Step Guide - CloudBlast"
description: "How to Create an HTML Server with Vert.x and Groovy: A Step by Step Guide"
url: "https://cloudblast.io/it/article/How-to-Create-an-HTML-Server-with-Vert.x-and-Groovy:-A-Step-by-Step-Guide"
language: "it-IT"
---

BLOG

# How to Create an HTML Server with Vert.x and Groovy: A Step by Step Guide

5€ DI SALDO GRATUITO alla registrazione

Registrati su CloudBlast e ricevi 5€ di credito cloud per distribuire i tuoi VPS

[Richiedi 5€ gratis](https://console.cloudblast.io/auth/login?ref=2)

-   [Indietro](https://cloudblast.io/it)
-   [Tutti gli articoli](https://cloudblast.io/it/blog)

2024-09-23

### How to Create an HTML Server with Vert.x and Groovy: A Step by Step Guide

tutorials

**Learn how to set up a Vert.x server using Groovy to serve HTML pages, including embedded JavaScript, CSS, and images.**

Vert.x is a versatile, event-driven application framework that runs on the Java Virtual Machine (JVM). It is known for its high performance and scalability, making it an excellent choice for building web servers. In this guide, we will walk through the process of creating an HTML server using Vert.x and Groovy, enabling you to serve web pages and static assets efficiently.

**Setting Up Your Development Environment**

Before we begin, ensure that you have the following installed on your system:

-   Java Development Kit (JDK) 8 or higher
-   Groovy
-   Maven or Gradle (for dependency management)

Once you have these tools installed, you can proceed to set up your Vert.x project.

**Creating a Vert.x Project**

To create a Vert.x project, you can use Maven or Gradle. Here, we'll demonstrate using Maven:

> ```
> <dependency>
>   <groupId>io.vertx</groupId>
>   <artifactId>vertx-core</artifactId>
>   <version>4.0.0</version>
> </dependency>
> <dependency>
>   <groupId>io.vertx</groupId>
>   <artifactId>vertx-web</artifactId>
>   <version>4.0.0</version>
> </dependency>
> <dependency>
>   <groupId>io.vertx</groupId>
>   <artifactId>vertx-lang-groovy</artifactId>
>   <version>4.0.0</version>
> </dependency>
> ```

Add these dependencies to your `pom.xml` file to include Vert.x core, Vert.x web, and Groovy support.

**Writing the Server Code**

Next, create a Groovy script to set up your Vert.x server. This script will handle HTTP requests and serve HTML content:

> ```
> import io.vertx.core.Vertx
> import io.vertx.ext.web.Router
>
> Vertx vertx = Vertx.vertx()
> Router router = Router.router(vertx)
>
> // Serve static resources
> router.route("/static/*").handler { routingContext ->
>   def file = routingContext.normalisedPath().substring(8) // Remove '/static/' prefix
>   routingContext.response().sendFile("webroot/$file")
> }
>
> // Serve HTML page
> router.route("/").handler { routingContext ->
>   routingContext.response()
>     .putHeader("content-type", "text/html")
>     .end("<html><body><h1>Welcome to Vert.x Server</h1></body></html>")
> }
>
> vertx.createHttpServer().requestHandler(router).listen(8080) { http ->
>   if (http.succeeded()) {
>     println("HTTP server started on port 8080")
>   } else {
>     println("HTTP server failed to start")
>   }
> }
> ```

This script sets up a basic HTTP server that listens on port 8080. It serves an HTML page at the root URL and static resources (such as CSS, JavaScript, and images) from the `webroot` directory.

**Serving Static Files**

To serve static files like CSS, JavaScript, and images, place them in a directory named `webroot` within your project. The server will automatically serve these files when requested.

**Running Your Server**

To run your server, execute the Groovy script using the following command:

> ```
> groovy YourServerScript.groovy
> ```

Open your web browser and navigate to `http://localhost:8080` to see your HTML page served by the Vert.x server.

**Conclusion**

By following this guide, you have successfully set up a basic HTML server using Vert.x and Groovy. This server can efficiently serve HTML pages and static assets, making it a powerful tool for web development. With Vert.x's scalability and performance, you can expand this setup to build more complex and dynamic web applications.

As you continue to explore Vert.x, consider integrating additional features such as templating engines, database connectivity, and real-time communication to enhance your web applications further.

Condividi

## Continua a leggere

[2026-07-25 How to Install and Set Up Mailcow on Ubuntu and Debian VPS tutorials](https://cloudblast.io/article/how-to-install-and-setup-mailcow-on-ubuntu-and-debian-vps)

[2026-07-25 How to Install Chatwoot on the Latest Ubuntu and Debian Server tutorials](https://cloudblast.io/article/how-to-install-chatwoot-on-ubuntu-and-debian-server)

[2026-07-25 How to Install Mattermost on the Latest Ubuntu and Debian Server tutorials](https://cloudblast.io/article/how-to-install-mattermost-on-ubuntu-and-debian-server)

[2026-07-25 How to Install RustDesk on the Latest Ubuntu and Debian Server tutorials](https://cloudblast.io/article/how-to-install-rustdesk-on-ubuntu-and-debian-server)
