java - 如何更改前端文件夹位置并在 Vaadin 14 中进行配置?

标签 java maven vaadin vaadin-flow vaadin14

如何将 Maven Vaadin 14 项目中的默认前端文件夹位置从 ${project.basedir}/frontend 更改为 ${project.basedir}/src/main/frontend ?

此外,Vaadin 插件在 maven 构建输出目录中输出前端文件夹,而不是我期望的 war exploded 目录。

既然我没有将这个文件夹映射到我的 web.xml 文件中,它是如何工作的?

如何让它将前端文件夹放入 war 存档中,并查看它使用哪个配置来使已编译的前端对我的应用程序可见?

最佳答案

Vaadin 在开发模式和生产模式中使用前端文件夹的方式不同。在生产中,它使用 build-frontend 目标构建前端。 Vaadin Maven 插件没有合适的文档,我发现最好的地方是解释每个目标的作用:https://vaadin.com/docs/v14/flow/production/tutorial-production-mode-advanced.html .此页面说明 build-frontend 负责在生产模式下构建并将处理的前端放入 WEB-INF\classes\META-INF\VAADIN\build 中。

开发模式非常不同,开发说明解释说,如果您不使用嵌入式服务器,您应该配置您的 IDE 以在部署前运行 prepare-frontend 目标:https://vaadin.com/docs/v14/flow/workflow/run-on-server-intellij.html .但是 prepare-frontend 只是将空的 frontend 文件夹创建到 target 中,如果文件夹是空的并且没有任何内容被复制到 war exploded 文件夹,它如何找到前端文件?回答:当您运行应用程序时,Vaadin 有一个 DevModeInitializer,它将文件 generated-flow-imports.js 创建到 target/frontend 中,它直接引用项目源文件,因此在它们可能会立即反射(reflect)出来,这就是为什么不需要在 web.xml 或上下文监听器中进行任何配置的原因。

Dev 模式对前端文件夹进行了某种破解,使开发更顺畅,而 prod 模式将前端的所有内容编译为由 Vaadin servlet 提供的缩小文件,因此只有在 prod 模式下,前端才会进入 war 文件。在第一种情况下,必须使用 prepare-frontend,在第二种情况下,也必须使用 build-frontend。因此,为了修改前端文件夹位置,必须更改这两个目标中的插件配置:

<plugin>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-maven-plugin</artifactId>
    <version>${vaadin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-frontend</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <frontendDirectory>${project.basedir}/src/main/frontend</frontendDirectory>
    </configuration>
</plugin>
<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>
                    <configuration>
                        <frontendDirectory>${project.basedir}/src/main/frontend</frontendDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile> 

这样,修改将在开发模式和生产模式下都有效。

关于java - 如何更改前端文件夹位置并在 Vaadin 14 中进行配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62479784/

相关文章:

java - JSP 中的多个按钮

java - 按长度分割字符串,保持子字符串完整

java - Android 获取上周日期

java - 断言 double 组精确相等

java - maven-source-plugin 构建了sources.jar,但 IDE 无法使用它

java - SplitPanel 组件中奇怪的渲染 SVG 元素

maven - maven-gpg-plugin 的正确执行阶段?

java - 部署 jar 文件时出现问题 : Error dependencies

java - Vaadin 无法将项目添加到网格

date - Vaadin - PopupDateField 不接受多种输入日期格式