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

编译ThingsBoard release-3.6源码后启动boot-jar报错求助

解决ThingsBoard 3.6编译后运行Jar找不到邮件模板文件的问题

问题核心

报错本质是代码试图用文件系统路径访问Jar包内的资源文件,但Jar中的资源并非独立的文件系统实体,因此触发FileNotFoundException。

具体解决步骤

  • 修复资源读取逻辑
    找到defaultTbMailConfigTemplateService类的初始化方法,替换掉依赖File或getResource().getFile()的代码,改用输入流读取Jar内资源:

    // 示例修正代码(基于Spring ResourceLoader)
    @Autowired
    private ResourceLoader resourceLoader;
    
    private void init() throws IOException {
        Resource resource = resourceLoader.getResource("classpath:templates/mail_config_templates.json");
        try (InputStream is = resource.getInputStream()) {
            // 读取流内容并处理
            String templateContent = new String(is.readAllBytes(), StandardCharsets.UTF_8);
            // 后续JSON解析逻辑...
        }
    }
    

    注意:getFile()仅适用于文件系统中的资源,完全无法处理Jar内的资源文件,必须改用输入流方式读取。

  • 验证打包完整性
    解压生成的thingsboard-3.6.1-SNAPSHOT-boot.jar,检查BOOT-INF/classes/templates/目录下是否存在mail_config_templates.json:

    • 如果文件不存在,先确认application模块的src/main/resources/templates/目录下有该文件,再检查模块pom.xml的resources配置是否正确包含资源目录:
      <resources>
          <resource>
              <directory>src/main/resources</directory>
              <includes>
                  <include>**/*</include>
              </includes>
          </resource>
      </resources>
      
    • 执行mvn clean package重新打包,确保资源被正确打入Jar。
  • 临时应急方案(不推荐长期使用)
    若暂时无法修改代码,可将mail_config_templates.json复制到Jar所在目录的templates子文件夹,通过系统参数指定外部资源路径启动:

    java -jar thingsboard-3.6.1-SNAPSHOT-boot.jar --spring.resources.static-locations=file:./templates/
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 06:13:33