You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Vaadin项目需同时保留根目录与UI模块frontend文件夹问题咨询

解决方案

问题根因

这是Vaadin多模块项目的常见路径匹配问题:默认启动时会以进程的工作目录(也就是项目根目录)为基准查找frontend主题目录,而编译运行时只会加载ui模块classpath下的frontend资源,所以导致需要双目录维护。

方法1:通过配置文件指定前端资源路径(推荐,开发生产都适用)

在ui模块的application.properties(或application.yml)中添加以下配置:

# 指定Vaadin查找前端资源的目录,指向ui模块下的frontend
vaadin.frontend.hotdeploy-directory=./ui/frontend
# 生产环境打包时扫描ui模块下的前端资源,替换为你ui模块的实际基础包名
vaadin.whitelisted-packages=com.yourproject.ui

如果使用yml格式配置:

vaadin:
  frontend:
    hotdeploy-directory: ./ui/frontend
  whitelisted-packages: com.yourproject.ui

注意:请确保@Theme(value = "myVaadinApp")中的主题名和ui/frontend/themes/下的文件夹名称完全一致,大小写敏感。

方法2:配置Maven插件同步资源(适合多模块复杂依赖场景)

在ui模块的pom.xml中,给vaadin-maven-plugin添加frontend目录配置:

<plugin>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-maven-plugin</artifactId>
    <version>${vaadin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-frontend</goal>
                <goal>build-frontend</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- 指定前端资源所在的目录为ui模块的frontend -->
        <frontendDirectory>${project.basedir}/frontend</frontendDirectory>
    </configuration>
</plugin>

验证步骤

  • 删除根目录下的./frontend文件夹
  • 重启应用,确认不会抛出主题找不到的异常
  • 修改ui/frontend/themes/myVaadinApp下的CSS样式,刷新页面确认样式生效

内容的提问来源于stack exchange,提问作者RaptoX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 04:54:04