无法使用 JDK16.0.2、JavaEE8.0.1、TomCat9.0.52、Vaadin14.6.8 使 helloworld 类型的程序运行

Can't get a helloworld type of program to work using JDK16.0.2, JavaEE8.0.1, TomCat9.0.52, Vaadin14.6.8

我通过下载这个来启动项目:https://github.com/vaadin/skeleton-starter-flow-cdi/archive/v14.zip

编辑 pom.xml 删除 tomEE 插件信息,因为我想单独 运行 它。我还添加了一个 maven-war 插件信息依赖项,以便我可以使用 Java16 进行编译。并将默认构建参数更改为 maven clean package 而不是 运行ning tomee 插件。我的 pom.xml 最终看起来像这样:

<?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.test</groupId>
    <artifactId>jee8tc9j16v14-6-8_hello001</artifactId>
    <name>JEE8TC9J16V14.6.8_hello001</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

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

        <!-- Dependencies -->
        <vaadin.version>14.6.8</vaadin.version>

        <drivers.dir>${project.basedir}/drivers</drivers.dir>
        <drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2/</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>

    <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>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-cdi</artifactId>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0.1</version>
            <scope>provided</scope>
        </dependency>

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

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

    <build>
        <defaultGoal>clean package</defaultGoal>
        <plugins>
            <!--
                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>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
            
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <!-- Runs the integration tests (*IT) after the server is started -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.22.2</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <trimStackTrace>false</trimStackTrace>
                            <enableAssertions>true</enableAssertions>
                            <systemPropertyVariables>
                                <!-- Pass location of downloaded webdrivers to the tests -->
                                <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>com.lazerycode.selenium</groupId>
                        <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                        <version>1.0.17</version>
                        <configuration>
                            <onlyGetDriversForHostOperatingSystem>true
                            </onlyGetDriversForHostOperatingSystem>
                            <rootStandaloneServerDirectory>
                                ${project.basedir}/drivers/driver
                            </rootStandaloneServerDirectory>
                            <downloadedZipFileDirectory>
                                ${project.basedir}/drivers/driver_zips
                            </downloadedZipFileDirectory>
                            <customRepositoryMap>
                                ${project.basedir}/drivers.xml
                            </customRepositoryMap>
                        </configuration>
                        <executions>
                            <execution>
                                <!-- use phase "none" to skip download step -->
                                <phase>${drivers.downloader.phase}</phase>
                                <goals>
                                    <goal>selenium</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我保持其他一切不变,然后通过 tomcat GUI (http://localhost:8080/manager/html) 部署构建的 .war 文件。
访问 http://localhost:8080/jee8tc9j16v14-6-8_hello001-1.0-SNAPSHOT/ returns this:

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Error instantiating servlet class [com.vaadin.cdi.CdiVaadinServlet]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Error instantiating servlet class [com.vaadin.cdi.CdiVaadinServlet]
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:831)
Root Cause

java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/BeanManager
    java.base/java.lang.Class.getDeclaredFields0(Native Method)
    java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3229)
    java.base/java.lang.Class.getDeclaredFields(Class.java:2335)
    org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:104)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:831)
Root Cause

java.lang.ClassNotFoundException: javax.enterprise.inject.spi.BeanManager
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1407)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)
    java.base/java.lang.Class.getDeclaredFields0(Native Method)
    java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3229)
    java.base/java.lang.Class.getDeclaredFields(Class.java:2335)
    org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:104)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:831)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.52

也许有人知道是什么导致了这些问题?也许我部署错了?也许 TomCat9 不能与此依赖项一起使用?

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0.1</version>
    <scope>provided</scope>
</dependency>

抱歉,如果这个问题看起来微不足道。我对这一切真的很陌生并且很挣扎所以非常感谢任何帮助! :)

Tomcat 仅实现 Java EE

的一小部分

Apache Tomcat 和 Eclipse Jetty 是 Servlet、JavaServer Pages 和 Java EE 中定义的极少数其他规范的两个竞争实现。但是 Java EE 定义了更多 在这些产品中实现的规范。这两种产品都非常受欢迎,因为它们提供的 Java EE 足以满足许多人的需求。

因此您不能在 POM 中指定完整的 Java EE API。 Tomcat 缺少大部分 API 的实现。

有关详细信息,请参阅 my Answer to the Question, Java EE Web Profile vs Java EE Full Platform。特别注意我的部分,Servlet-oriented (Tomcat & Jetty).

您确实可以仅使用 Tomcat 或 Jetty 构建 Vaadin 网络应用程序。我自己交付过这样的应用程序,运行部署到 Apache Tomcat 时效果很好。 Vaadin 的一些默认 POM 在 IDE 中包含对 运行 Jetty 的 Maven 操作。我们在下面的 Steps 部分中使用它。

看你第一句话中的 URL,我看到你通过下载 CDI 的骨架启动器开始了你的项目。 “CDI”是 Contexts and Dependency Injection,Tomcat 未实现的众多 Java EE 规范之一。因此 POM 被设置为完整 Java EE API.

➥ 您可以下载不同的没有 CDI 的 Skeleton Starter,也没有完整的 Java EE API.

你说:

new to all of this and struggling quite a bit so any help is really greatly appreciated! :)

是的,web apps, web containers, Maven/Gradle, Vaadin, Java, Servlets, and IDEs 的工具是复杂、挑剔、令人沮丧和烦人的。更糟糕的是,所有这些都在不断变化!我只能说,要坚持,要固执,要坚持。并反复搜索 Stack Overflow——这里涵盖了很多问题和方面,其中一些是我自己经历的磨难。

步骤

这里是步骤大纲,但不是完整的教程。

一定要在 Vaadin.com 网站和 YouTube 上查看教程。特别是,Marcus Hellberg 最近发布了很好的教程。另外,如果你真的卡住了,Vaadin Ltd 公司出售咨询和培训服务。

如果您 Mac 使用 Apple Silicon(M1 芯片)而不是 Intel,请确保您已安装 Rosetta 2。安装 Intel-only 应用程序,例如 Unicode Checker 将提示安装。这里的问题是 Vaadin 使用了一些 JavaScript 工具(Node.js & npm),这些工具仍然仅限于 Intel ,即使是一年后的现在,也就是 2021 年底。

下载 skeleton-starter-flow-14

Start page at Vaadin.com, click the link further down 上下载普通的 Java 启动器。在下一页上,查找 Vaadin 14 - plain Java 块。请注意,我们 想要 Vaadin 14 - Spring Boot 块,也不想要 Vaadin 14 - CDI块。

该块中的 link 下载 skeleton-starter-flow-14 文件夹。您可以更改名称,并将该文件夹重新定位到您的 IDE 项目的常用位置。

第一个运行

在 IDE 中打开下载的文件夹。稍等片刻,Maven 正在执行其操作、解包、下载等。同时,请阅读 README.md 页面。

Maven 安静后,按原样构建项目。您 IDE 可能有办法在其 GUI 中调用 Maven。例如,IntelliJ 有一个 Maven 工具面板。在那里我们应该 运行 clean,然后 install.

如果您收到错误消息“未找到有效的 Maven 安装。”,请参阅 this Question, and this Answer 指导您将“Maven 包装器”设置切换为“捆绑 Maven”。是的,这是所有这些工具中许多愚蠢的减速带之一。

如果您收到“无法访问属性的默认字段”错误,请参阅 this Question with this Answer, leading to this Maven documentation page 告诉您要添加到 POM 中的内容。是的,这是工具中许多愚蠢的减速带中的另一个。让 Maven 重新处理 POM — 在 IntelliJ 中,这意味着单击带有微小 Maven 徽标的微小浮动小 windoid。

当您成功将 cleaninstall 转换为 运行 时,您就可以 运行 网络应用程序了。在 IntelliJ 中,我转到那个 Maven 工具窗格,然后导航到 Vaadin 的项目库 > Plugins > jetty > 码头:运行。等待几分钟,尤其是第一次,因为可能需要下载更多的项目,Vaadin 使用的各种工具必须 运行.

最终您会在控制台上看到一条消息,指出“已启动 Jetty 服务器”。这意味着您可以切换到网络浏览器,然后指向 http://localhost:8080/。您应该会看到示例应用程序,提示您输入姓名,并带有一个“问好”按钮。尝试该字段和按钮,以确保一切正常。

现在回到IDE。停止 Jetty Web 容器。在IntelliJ中,我点击整体window.

右上角的红色方块图标

Java 16

更新: Java 16 现已停产。我建议您转到 Java 17,即当前的长期支持 (LTS) 版本。

您想使用 Java 16,所以我们需要再次回到我们的 POM。替换这两行:

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

…与:

        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>

或者使用这个在更高版本的 Maven 工具中工作的“release”标签:

        <maven.compiler.release>16</maven.compiler.release>

保存 POM 文件。让 Maven 重新加载这个编辑过的 POM。在 IntelliJ 中,这意味着单击带有微小 Maven 徽标的微小浮动小 windoid。

再做一个 Maven clean & install 以取得良好效果。

您可能会更新:

        <jetty.version>9.4.43.v20210629</jetty.version>

… 或:

        <jetty.version>10.0.6</jetty.version>

…以及以下项目。您的 IDE 或许能够查找最新版本号。在 IntelliJ 中,删除版本号并按 Control+Space(如果我没记错的话,在 macOS 上)。

        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>4.4.3</version>
            <scope>test</scope>
        </dependency>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.0.0-M5</version>

将编辑保存到您的 POM。让您的 IDE 重新处理该 POM。再做一个 Maven clean & install。也许请 IDE 重建项目,祝你好运。然后 运行 具有该 jetty:run 操作的网络应用程序。将您的网络浏览器指向 http://localhost:8080/。您的应用应该再次 运行。

示例 POM

这是我完成的 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>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>

        <vaadin.version>14.6.8</vaadin.version>
        <jetty.version>9.4.43.v20210629</jetty.version>
    </properties>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</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>
        <!-- Maven Central repository requires https:// to access -->
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</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>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </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>3.1.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>4.4.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <!-- Basil added-->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.3.1</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <defaultGoal>jetty:run</defaultGoal>
        <plugins>
            <!-- Basil added-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <!-- Jetty plugin for easy testing without a server -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <!-- If using IntelliJ IDEA with autocompilation, this
                    might cause lots of unnecessary compilations in the
                    background.-->
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <!-- 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>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>${jetty.version}</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>deploy-war</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-M5</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>

Tomcat

如果运行正常,请再次停止 Jetty 服务器。现在,我们可以尝试 Tomcat 9.0.52.

查看项目的 target 文件夹。您应该找到 WAR file,名称类似于 project-base-1.0-SNAPSHOT.war。将该文件复制到 Tomcat 的 webapps 文件夹中。根据需要重命名,例如 demo.war.

开始 Tomcat。将浏览器指向 http://localhost:8080/。您应该会看到“Apache Tomcat/9.0.52”页面。

将您的浏览器指向 http://localhost:8080/demo/demo 与您在 WAR 文件中的名字相匹配。您应该会看到示例 Vaadin 应用 运行ning。瞧!

希望这能帮助您在 Vaadin 工作中更进一步。