如何从Vaadin 23升级至Vaadin 24?
升级Vaadin 23.3.1项目至Vaadin 24预发布版本
我使用Vaadin官网下载的Plain Java入门应用,已将Maven POM更新至Vaadin 23.3.1、Java 19、jetty-maven-plugin 10.0.12等最新依赖版本。现在希望尝试Vaadin 24的预发布版本——该版本核心目标是完成从Java EE 8到Jakarta EE 10的过渡,主要变更包括移除部分废弃特性、将所有javax.*包名切换为jakarta.*,属于Java EE捐赠给Eclipse基金会转为Jakarta EE的关键过渡环节。
核心修改点说明
以下是针对现有POM的具体调整内容,直接替换对应部分即可完成升级:
1. 更新Vaadin版本属性
将<vaadin.version>改为Vaadin 24的预发布版本号(示例为24.0.0.beta1,可按需替换为最新预发布版本):
<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.beta1</vaadin.version> <!-- 替换为Vaadin 24预发布版本 --> <drivers.downloader.phase>pre-integration-test</drivers.downloader.phase> </properties>
2. 替换Servlet API依赖(javax → jakarta)
移除原Java EE的javax.servlet-api依赖,替换为Jakarta EE 10对应的jakarta.servlet-api:
<!-- 删除原有依赖 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <!-- 添加Jakarta版本依赖 --> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency>
3. 升级Jetty插件版本
Vaadin 24基于Jakarta EE 10,需使用支持该规范的Jetty 11版本:
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>11.0.15</version> <!-- 升级至Jetty 11 --> <configuration> <scan>2</scan> </configuration> </plugin>
4. 代码层面补充调整
项目代码中所有导入的javax.*相关包(如javax.servlet、javax.annotation等)需手动替换为jakarta.*;若使用其他Java EE相关依赖(如JPA、CDI),也需同步替换为对应的Jakarta EE版本。
修改后的完整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.beta1</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> <!-- Jakarta Servlet API for Jakarta EE 10 --> <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.15</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> <version>11.0.15</version> <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>
内容的提问来源于stack exchange,提问作者Basil Bourque
相关产品推荐
相关产品推荐

