Add Vaadin to Java Maven Project

I have a Java project with maven and want to add Vaadin to it for UI creation.
What do I have to add to the dependencies?
I found this: https://vaadin.com/docs/latest/tools/mpr/introduction/1-maven-v8
but I think that’s a little outdated and also looks like more dependencies than I need.
I tried to add the following dependencies to my pom.xml:

<dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
</dependency>
<dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core</artifactId>
</dependency>

with this property set: <vaadin.version>24.3.6</vaadin.version>
Now, for the first dependency the integration works, for vaadin-core I get the error shown in the screenshot.
Screenshot_4.png

The article you’re reading for Multiplatform Runtime, which allows running /using multiple vaadin versions at the same time, if I remember correctly. I’ll take a look at what you actually need.

Actually, simplest way is to likely just work from an example, in which case, you can create a start project here, that is based on maven:
https://start.vaadin.com/

In the start project you’ll also find necessary build profile adjustments, necessary repositories, dependencyManagement setup… and outside of the pom.xml stuff, you’ll also have a the folder structure and additional nessessary and example files.

And if you’ll need spring security as well, make sure you modify a view in the editor, change its View Access to something other than Public.
image.png

Afterwards just click the “Export Project” button, to export the project files.

The thing is, I already have a project with some code and a database.

I’ll download the Hello World project and see if I can copy the dependencies from the pom

Of course, that’s how I thought you’d use it anyway, just to compare, and see what’s required in a fresh vaadin project. And you’ll also have a copy to test some vaadin functionality if it’s not working in your project.

ok, I got rid of the error in my pom at least using these properties and dependencies:

<properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <vaadin.version>24.3.6</vaadin.version>
</properties>

<repositories>
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
</repositories>

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

<dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-bom</artifactId>
            <version>${vaadin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core</artifactId>
        </dependency>
</dependencies>

I’m not sure if I should also use this build section:

<build>
        <defaultGoal>spring-boot:run</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>

I’m not using spring right now.

then you can check some other starter examples, whether its some other framework it’s based on, or if its just Plain Java:
https://vaadin.com/docs/latest/guide/start#non-spring-boot-starters

those projects also have spring included. I mean, I can add spring. Does Vaadin require spring?

It’s optional

Here’s a starter for a Flow application without Spring GitHub - vaadin/skeleton-starter-flow: Default project template for Vaadin

I’ll try that. Looking at the example code. I can’t see any main method in src/main/java/…
Where does the application start when executed?

It’s a servlet based application with jetty; there is no such thing as a main method - that’s just a spring boot thing.

it’s also a java thing. But I’ll have to look into how this works then. I somewhat expected the java main method to run and start the UI to then interact via vaadin with the java code, database etc.

See the readme: Run using mvn jetty:run and open http://localhost:8080 in the browser.

when I type mvn jetty:run in the starter project skeleton-starter-flow linked by marcoc_753 I get an error unknown command