代码之家  ›  专栏  ›  技术社区  ›  Basil Bourque

如何从Vaadin 23升级到Vaadin 24?

  •  0
  • Basil Bourque  · 技术社区  · 2 年前

    我用了 纯Java 启动器应用程序 Hello World Starters 下载页面。

    我将其Maven POM更新为最新版本的依赖项。所以Vaadin 23.3.1、Java 19、jetty-maven插件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 .

    1 回复  |  直到 1 年前
        1
  •  7
  •   Basil Bourque    1 年前

    官方指示,加上我的详细信息

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

    首先,迁移到最新的Vaadin 23

    该页面首先指示我们迁移到Vaadin 23的最新版本,目前为23.3.5。我们看到你做了你现有的Maven POM 文件。

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

    Java版本

    该页面说,接下来要确保您的项目可以在 Java 17 ,最新 long-term support 版本。

    我们看到你在现有的POM中也这样做了,运行 Java 19 (the current Java release ).

    Vaadin版本

    官方指示指向我们 this GitHub page 获取Vaadin 24的最新版本。我们发现 24.0.0.alpha10 .

    因此,我们将该版本号粘贴到POM中。

    Servlet规范

    接下来,寻找 javax.servlet-api 在POM中输入。

    Vaadin 23及更早版本的设计用于 Java Servlet Specification 版本3.1,与Java Servlet规范4.0.1兼容。

    当我们跳到Jakarta 10时,规范的名称更改为 Jakarta Servlet .还有 Servlet Spec is version 6 雅加达EE 10。我们可以使用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 但12号在 阿尔法 截至2023年1月。如果好奇,请在YouTube上观看2022-04年的演讲, 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.13 属于 jetty maven插件 使用码头5。

    <!-- 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 disabeld 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>
    

    让我们试试吧,祝你成功!使用 配备Vaadin 24的嵌入式Jetty 11正在运行 至少目前是这样。

    好的

    这就是我们将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>
    

    外部应用服务器

    您可能希望IDE使用外部应用服务器执行,而不是使用上面讨论的嵌入式Jetty。

    如果是这样,您需要使用支持Jakarta EE 10的所需服务器版本。这是一份部分清单。

    • Apache Tomcat 10.1
    • Eclipse码头12
    • 日蚀玻璃鱼7
    • 帕亚拉6
    • IBM开放自由22
    • 红帽WildFly 27
    • 以及更多