【问题标题】:How to upgrade from Vaadin 23 to Vaadin 24?如何从 Vaadin 23 升级到 Vaadin 24?
【发布时间】:2022-12-24 11:10:09
【问题描述】:

我用了纯Java来自 Hello World Starters 下载页面的入门应用程序。

我将其 Maven POM 更新为最新版本的依赖项。所以 Vaadin 23.3.1、Java 19、jetty-maven-plugin 10.0.12 等等。 POM 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>project-base</artifactId>
    <name>Project base for Vaadin</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>

        <vaadin.version>23.3.1</vaadin.version>
        <drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
    </properties>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>vaadin-prereleases</id>
            <url>
                https://maven.vaadin.com/vaadin-prereleases/
            </url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- Repository used by many Vaadin add-ons -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>vaadin-prereleases</id>
            <url>
                https://maven.vaadin.com/vaadin-prereleases/
            </url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

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

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
        </dependency>

        <!-- Added to provide logging output as Vaadin uses -->
        <!-- the unbound SLF4J no-operation (NOP) logger implementation -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-testbench</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>jetty:run</defaultGoal>
        <plugins>
            <!-- Define newer versions of Java compiler and war plugin to 
                 better support the latest JDK versions. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
            <!-- Jetty plugin for easy testing without a separate server -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>10.0.12</version>
                <configuration>
                    <!--
                    Configures automatic reload of Jetty server
                    (with 2 second timeout) when new classes are compiled 
                    (e.g. by IDEs).
                    Should be disabled when using a proper live reload system,
                    such as JRebel.
                    If using IntelliJ IDEA with autocompilation, this
                    might cause lots of unnecessary compilations in the
                    background. Consider using "0" and trigger restart manually
                    by hitting enter.
                    -->
                    <scan>2</scan>
                    <!-- Use war output directory to get the webpack files -->
                    <!--<webAppConfig>-->
                    <!--    <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>-->
                    <!--</webAppConfig>-->
                </configuration>
            </plugin>

            <!--
                Take care of synchronizing java dependencies and imports in
                package.json and main.js files.
                It also creates webpack.config.js if not exists yet.
            -->
            <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>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <productionMode>true</productionMode>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <!--<scanIntervalSeconds>0</scanIntervalSeconds>-->
                            <stopPort>8081</stopPort>
                            <stopWait>5</stopWait>
                            <stopKey>${project.artifactId}</stopKey>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-jetty</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-jetty</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Runs the integration tests (*IT) after the server is started -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.0.0-M7</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <trimStackTrace>false</trimStackTrace>
                            <enableAssertions>true</enableAssertions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我多么想尝试 Vaadin 24 的预发布。

我了解此新版本在功能或修复方面几乎没有新内容。相反,这个新版本旨在实现从基于 Java EE 8 到基于 Jakarta EE 10 的过渡。如this Vaadin company blog page 中所述,这一飞跃涉及 (a) 删除一些已弃用的功能,以及 (b)将包名称从javax.* 切换为jakarta.*。这些更改是从 Oracle 捐赠 Java EE 技术到 Eclipse Foundation 成为 Jakarta EE 的过渡的一部分。

【问题讨论】:

    标签: jakarta-ee migration vaadin vaadin-flow javaee


    【解决方案1】:

    官方说明,加上我的详细信息

    Vaadin 公司博客页面 Vaadin 24 pre-release available for Spring Boot 3.0 提供了一些从 Vaadin 23 迁移到 Vaadin 24 的说明。我可以用更多详细信息补充该页面。

    首先,迁移到最新的 Vaadin 23

    该页面首先指示我们迁移到最新版本的 Vaadin 23,目前为 23.3.1。我们看到您对现有的 Maven POM 文件进行了操作。

    在尝试 Vaadin 24 之前,请确保运行您的应用程序以验证 Vaadin 23 是否正常运行。

    Java版

    该页面说接下来要确保您的项目可以在 Java 17 上运行。我们看到您在现有的 POM 中也这样做了,在 Java 19(当前的 Java 版本)上运行。

    Vaadin 版本

    接下来我们检查 this GitHub page 以捕获当前最新版本的 Vaadin 24。目前是 24.0.0.alpha6。所以我们将其粘贴到 POM 中。

    Servlet规范

    接下来,在您的 POM 中查找 javax.servlet-api 条目。

    Vaadin 23 及更早版本是为Java Servlet Specification 3.1 版设计的,并且与 Java Servlet Spec 4.0.1 兼容。

    当我们跳转到 Jakarta 10 时,规范的名称更改为 Jakarta Servlet。以及 Jakarta EE 10 中的 Servlet Spec is version 6。我们可以使用 Maven 存储库(例如 this one)验证 Servlet 6 的最新版本是 6.0.0

    所以我们更改 POM 的这一部分:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
    </dependency>
    

    … 到:

    <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>
    

    码头

    您的 Vaadin 23 应用程序与嵌入式版本的 Jetty 捆绑在一起。这使您能够使用 Jetty 作为部署 Web 应用程序服务器来运行 Vaadin Web 应用程序之内你的IDE。这种安排很方便,可以减轻您配置外部 Web 应用程序服务器的繁重工作。

    尽管如此,您仍然可以选择使用在其自己的进程中运行的外部 Web 应用程序服务器,例如 Tomcat、单独安装的 Jetty、Glassfish、WildFly、Payara、OpenLiberty 或任何其他此类产品。但是,如果您希望在 IDE 中使用嵌入式 Jetty,请继续阅读。

    您现有的 POM 设置为使用 jetty-maven-plugin 版本 10.0.x。这对应于 Jetty 10。Jetty 的那个版本支持 Servlet 4。

    但是我们正在转向 Servlet 6。这需要不同版本的 Jetty,即 Jetty 12。不幸的是,Jetty 12 似乎仍在开发中,hosted on GitHub。但是还没有发布。如果好奇,请在 YouTube 上观看这个 2022 年 4 月的演讲,Jakarta Tech Talk - Implementing Servlet 6.0 in Jetty

    所以我们有一个困境,如果我们想在我们的 IDE 中方便地运行嵌入的 Jetty。从技术上讲,Vaadin 24 是为 Jakarta 10 构建的,这意味着 Servlet 6。但是我们只有 Jetty 11 可用,它支持 Servlet 5 而不是 Servlet 6。但也许我们可能幸运地发现 Vaadin 24,因为它没有显着Vaadin 23 的功能更改,实际上可能没有使用仅在 Servlet 6 中可用的任何新功能,也没有使用从 Servlet 6 中删除的任何旧功能。如果是这样,我们可能会使用 11.0.13jetty-maven-plugin 版本来利用5 号码头。而且……是的,我找到了成功!将嵌入式 Jetty 11 与 Vaadin 24 一起使用是可行的,至少目前是这样。

    这就是我们将您的 Vaadin 23 应用程序迁移到 Vaadin 24 (alpha 6) 所需要做的全部工作。

    您可以使用 Maven Jetty 插件命令 jetty:run 来启动您的 Web 应用程序,就像您使用 Vaadin 23 一样。

    这是我生成的 Maven POM 文件。

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns = "http://maven.apache.org/POM/4.0.0"
             xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>project-base</artifactId>
        <name>Project base for Vaadin</name>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <properties>
            <maven.compiler.source>19</maven.compiler.source>
            <maven.compiler.target>19</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <failOnMissingWebXml>false</failOnMissingWebXml>
    
            <vaadin.version>24.0.0.alpha6</vaadin.version>
            <drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
        </properties>
    
        <repositories>
            <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
            <repository>
                <id>central</id>
                <url>https://repo.maven.apache.org/maven2</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>vaadin-prereleases</id>
                <url>
                    https://maven.vaadin.com/vaadin-prereleases/
                </url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <!-- Repository used by many Vaadin add-ons -->
            <repository>
                <id>Vaadin Directory</id>
                <url>https://maven.vaadin.com/vaadin-addons</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
    
        <pluginRepositories>
            <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->
            <pluginRepository>
                <id>central</id>
                <url>https://repo.maven.apache.org/maven2</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>vaadin-prereleases</id>
                <url>
                    https://maven.vaadin.com/vaadin-prereleases/
                </url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-bom</artifactId>
                    <type>pom</type>
                    <scope>import</scope>
                    <version>${vaadin.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <!-- Replace artifactId with vaadin-core to use only free components -->
                <artifactId>vaadin</artifactId>
            </dependency>
    
            <!-- Added to provide logging output as Vaadin uses -->
            <!-- the unbound SLF4J no-operation (NOP) logger implementation -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
            <dependency>
                <groupId>jakarta.servlet</groupId>
                <artifactId>jakarta.servlet-api</artifactId>
                <version>6.0.0</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-testbench</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
            <dependency>
                <groupId>io.github.bonigarcia</groupId>
                <artifactId>webdrivermanager</artifactId>
                <version>5.3.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <defaultGoal>jetty:run</defaultGoal>
            <plugins>
                <!-- Define newer versions of Java compiler and war plugin to 
                     better support the latest JDK versions. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.3.2</version>
                </plugin>
                <!-- Jetty plugin for easy testing without a separate server -->
                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>11.0.13</version>
                    <configuration>
                        <!--
                        Configures automatic reload of Jetty server
                        (with 2 second timeout) when new classes are compiled 
                        (e.g. by IDEs).
                        Should be disabled when using a proper live reload system,
                        such as JRebel.
                        If using IntelliJ IDEA with autocompilation, this
                        might cause lots of unnecessary compilations in the
                        background. Consider using "0" and trigger restart manually
                        by hitting enter.
                        -->
                        <scan>2</scan>
                        <!-- Use war output directory to get the webpack files -->
                        <!--<webAppConfig>-->
                        <!--    <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>-->
                        <!--</webAppConfig>-->
                    </configuration>
                </plugin>
    
                <!--
                    Take care of synchronizing java dependencies and imports in
                    package.json and main.js files.
                    It also creates webpack.config.js if not exists yet.
                -->
                <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>
    
        <profiles>
            <profile>
                <!-- Production mode is activated using -Pproduction -->
                <id>production</id>
    
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.vaadin</groupId>
                            <artifactId>vaadin-maven-plugin</artifactId>
                            <version>${vaadin.version}</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>build-frontend</goal>
                                    </goals>
                                    <phase>compile</phase>
                                </execution>
                            </executions>
                            <configuration>
                                <productionMode>true</productionMode>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
    
            <profile>
                <id>it</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-maven-plugin</artifactId>
                            <configuration>
                                <!--<scanIntervalSeconds>0</scanIntervalSeconds>-->
                                <stopPort>8081</stopPort>
                                <stopWait>5</stopWait>
                                <stopKey>${project.artifactId}</stopKey>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>start-jetty</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>start</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>stop-jetty</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
    
                        <!-- Runs the integration tests (*IT) after the server is started -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>3.0.0-M7</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>integration-test</goal>
                                        <goal>verify</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <trimStackTrace>false</trimStackTrace>
                                <enableAssertions>true</enableAssertions>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2022-12-22
      • 2016-12-04
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多