Docs

Documentation versions (currently viewingVaadin 24)

Project Structure

The basics of structuring and packaging Vaadin projects.

A Vaadin project is essentially a Spring Boot project, managed with Maven. As a result, if you’re familiar with and already use Spring Boot, probably how you structure projects can work well with Vaadin.

If Spring Boot or Maven are new to you, though, you should first familiarize yourself with them before proceeding. Maven has a Getting Started Guide that you’ll find helpful. Spring Boot has an extensive reference manual that includes a tutorial.

JAR vs. WAR

Whenever you build a web application with Spring Boot, you have to decide whether to package it as a JAR file or as a WAR file. This also applies to Vaadin applications. Both approaches have their own pros and cons, which are presented in the sections that follow.

JAR File Packaging

Packaging a Vaadin application as a JAR file is the recommended choice. It contains everything needed to run an application, except for the Java Virtual Machine. The web server — like Tomcat, Jetty, or Undertow — is embedded. Therefore, you can start an application by running this command:

$ java -jar <your-app>.jar
Important
For this command to work, you have to build the application in production mode.

This makes the deployment simple and with a few options. To deploy an application to a containerized environment, you can convert it into a container image. To deploy instead to a virtual or physical Linux server, you can run it as a service by using either init.d or systemd. And to deploy to a Windows server, you can use WinSW to run it as a Windows service.

Another advantage to packaging an application as a JAR file is that it’ll run inside its own Java Virtual Machine, and therefore its own operating system process. This allow you to configure and restart it without affecting other applications. Plus, if the application is compromised or crashes, other applications running on the same physical server are better protected since they run in their own processes. This feature, though, comes with a cost.

Since every application runs an embedded web server, they consume more memory and disk space than a traditional Java web application. However, since memory and disk space are quite cheap, the cost is usually well worth the benefits.

WAR File Packaging

Vaadin applications can also be packaged as traditional Java web applications. The resulting WAR file must be deployed, though, to an external web application server. You can use an open source server (e.g., Tomcat, Jetty, or Undertow). Or you can use a commercial server (e.g., JBoss or WebLogic).

A WAR file contains only the application and any dependencies not provided by the web application server. It’s therefore smaller than a self-contained JAR file. Multiple WAR files can be deployed to the same web application server. Since the applications run inside the same JVM, the memory overhead is smaller compared to running each inside its own JVM. The drawback to this approach is that if something happens to the JVM process (e.g., a memory or thread leak), all of the applications are affected.

You should only consider WAR packaging if you already have a web application server, or if you need advanced features that are available only from a specific web application server. Otherwise, packaging as a JAR file is better.

Multi vs. Single-Module

You can build your Vaadin applications as single-module Maven projects, or as multi-module Maven projects. Both options have advantages and disadvantages. You should familiarize yourself with them before making a decision.

You can find more information on the Single-Module Projects, and the Multi-Module Projects documentation pages.