What Javalin is
Javalin is a small web framework for Java and Kotlin. It starts an HTTP server right from the main method and lets you say in a few lines: "answer a GET /posts request with the list of posts". There are no annotations, no class scanning and no hidden magic: you see the whole path of a request in your own code. That makes Javalin a good first step into server-side Java.
How Javalin works
Inside Javalin runs Jetty, a proven web server written in Java. You do not install it separately: it comes as an ordinary Maven dependency and starts together with your program. Such a server is called embedded.
Application code consists of three kinds of parts:
| Part | What it does |
|---|---|
| Route | Connects an HTTP method and an address, such as GET /posts, to code |
| Handler | A lambda or method that receives the request and builds the response |
Context ctx | An object with the request data and methods for the response |
Javalin and big frameworks
| Javalin | Spring Boot, Quarkus | |
|---|---|---|
| Size | One library | A platform of many modules |
| Configuration | Plain Java code | Annotations and settings files |
| Dependency injection | None, you create objects yourself | Built in |
| Entry barrier | Low | Higher |
Javalin does not hide how a web server works, so it is a convenient place to understand what a route, a response status or JSON is. Later this knowledge carries over to any other framework.
Version in this course
The course is written for Javalin 7.2 and Java 25. Javalin 7 needs Java 17 or newer and runs on Jetty 12. Version 7 changed the style: all routes are declared inside the configuration block Javalin.create(config -> ...). In older articles you will see calls like app.get(...) after the server has started — Javalin 7 does not have them.
Check that Java and Maven are installed:
java -version
mvn -versionBoth commands should print versions: Java 25 (21 also works) and Maven 3.9.
What we will build
Throughout the course we build a REST API for a blog:
/postsroutes for listing, viewing, creating and deleting posts.- JSON, data validation and clear errors.
- Controllers, static files, HTML templates, forms and file uploads.
- An H2 database through JDBC, password login with roles, CORS, cookies and sessions, API documentation in Swagger UI.
- A WebSocket chat, SSE notifications, tests, a build into a single jar file, settings from the environment and a request log.
We send requests to the API with the curl utility. The commands in the lessons are written for bash: Linux, macOS or Git Bash on Windows.
Common mistake
Maven runs the compiler of the Java that the JAVA_HOME variable points to. If an old version is still there, building the project from this course fails on the very first command:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.1:compile
(default-compile) on project blog: Fatal error compiling: error: release version 25 not supported
The Java 16 compiler does not know version 25. If you lower the version in the project, the error just moves to startup: UnsupportedClassVersionError ... (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0 — the Javalin classes are built for Java 17. Install JDK 25 and make sure JAVA_HOME points to it.