如何从Vaadin 23升级到Vaadin 24



我使用了Hello World Starters下载页面中的Plain Java入门应用程序。

我将其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>

现在我想试试Vaadin24的预发布。

我知道这个新版本在功能或修复方面几乎没有什么新的。相反,这个新版本旨在从基于Java EE 8过渡到基于Jakarta EE 10。正如Vaadin公司博客页面中所讨论的,这一飞跃涉及(a)删除一些不推荐使用的功能,以及(b)将包名称从javax.*切换到jakarta.*。这些变化是从Oracle向Eclipse基金会捐赠Java EE技术转变为Jakarta EE的一部分。

官方说明,以及我的详细信息

Vaadin公司的博客页面Vaadin24预发布版可用于SpringBoot3.0,提供了从Vaadin23迁移到Vaadin24的一些说明。我可以用更多的细节来补充那一页。

首先,迁移到最新的Vaadin 23

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

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

Java版本

该页面表示,接下来要确保您的项目能够在最新的长期支持版本Java17上运行。

我们看到您在现有的POM中也这样做了,它运行在Java19(当前的Java版本)上。

Vaadin版本

官方说明将我们指向这个GitHub页面,以获取Vaadin24的当前最新版本。在那里我们找到了24.0.0.alpha10

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

Servlet规范

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

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

当我们跳到Jakarta 10时,规范的名称更改为Jakarta Servlet。Servlet规范是Jakarta EE 10中的第6版。我们可以用像这样的Maven存储库来验证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作为IDE内的部署web应用服务器来运行Vaadin web应用程序。这种安排很方便,免去了配置外部web应用程序服务器的繁琐工作。

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

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

但我们正在转向Servlet 6。这需要一个不同版本的Jetty,Jetty 12。不幸的是,Jetty 12似乎仍在开发中,托管在GitHub上。但截至2023-01年,12人处于阿尔法阶段。如果好奇,请在YouTube上观看这篇2022-04年的演讲,雅加达技术演讲-在Jetty中实现Servlet 6.0

因此,如果我们想在IDE中方便地运行嵌入的Jetty,我们就陷入了困境。从技术上讲,Vaadin 24是为雅加达10建造的,这意味着Servlet 6。但我们只有Jetty 11,它支持Servlet 5而不是Servlet 6。但也许我们很幸运地发现,Vaadin 24与Vaadin 23相比没有显著的功能变化,实际上可能没有使用任何仅在Servlet 6中可用的新功能,也没有使用从Servlet 6中删除的任何旧功能。如果是这样的话,我们可以使用jetty-maven-plugin11.0.13版本来使用Jetty 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>

让我们试试吧,祈祷吧🤞 …是的,成功!将嵌入式Jetty 11与Vaadin 24一起使用是可行的,至少目前是这样。

Voilà

这就是我们将您的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 Jetty 12
  • Eclipse GlassFish 7
  • Payara 6
  • IBM Open Liberty 22
  • Red Hat WildFly 27
  • …等等

最新更新