Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Packaging a Theme for Reuse

A custom theme can be packaged into a JAR file for use in multiple applications as follows:

  1. Create a new Maven project with the following structure and add your theme files to the theme folder (1):

    [project root]
    ├── src
    │   └── main
    │       └── resources
    │           └── META-INF
    │               └── resources
    │                   └── themes
    │                       └── my-theme  (1)
    └── pom.xml
  2. Update pom.xml as follows:

    • Add the Vaadin version property:

    • Add dependency management:

    • Update dependencies to only contain the following:

  3. If the theme uses npm assets, as described in Style Sheets From npm Packages, add a class (1) with the corresponding @NpmPackage annotations:

    [project root]
    └── src
        └── main
            └── java
                └── com
                    └── vaadin
                        └── flow
                            └── theme
                                └──  (1)
    Dependency class package
    The package in which the java class is placed doesn’t have to be com.vaadin.flow.theme package as in the example above, but it’s recommended for themes that are going to be used in Vaadin Spring Boot applications, as it’s always automatically scanned. Other recommended packages are com.vaadin.flow.component and com.vaadin.shrinkwrap. See Vaadin’s Spring package scanning documentation for using other custom packages.
  4. Create the JAR with mvn install.

To use the packaged theme in an application, add the JAR as a dependency and apply the theme using the @Theme annotation.