【问题标题】:Vaadin 10 and springboot - How to package a jar?Vaadin 10 和 springboot - 如何打包 jar?
【发布时间】:2018-10-09 20:31:56
【问题描述】:

问题很简单,但我在过去 2 天里试图部署我的应用程序。到目前为止还没有。

我的样式只有一个 css 文件,当我执行 jar 时,找不到 css (404) 或者 jar 不会打包。

如此处所述:Spring Boot Executable jar structure “如果您的应用程序将被打包为 jar,请不要使用 src/main/webapp 文件夹” 和 “您应该将静态资源放在 src/main/resources 中。”

所以把css放在这里: src/main/resources/styles.css

在 Vaadin 文档中(关于如何打包...)我像这样导入 css:

@StyleSheet("styles.css")

来源:https://vaadin.com/docs/v11/flow/importing-dependencies/tutorial-include-css.html

然后我打包我的项目:

 mvn clean package -Pproduction

我得到这个错误:

[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:11.0.0:package-for-production (default) on project importparcoursup: Execution default of goal com.vaadin:vaadin-maven-plugin:11.0.0:package-for-production failed: An import that ends with 'styles.css' cannot be resolved: the corresponding file 'C:\Workspace\lasteclipeandjava10\parcoursup\target\frontend\styles.css' was not found.
[ERROR] Double check the corresponding import and verify the following:
[ERROR] * the import string is correct
[ERROR] * the file imported is either present in 'frontend://' directory of the project or in one of the project WebJar dependencies or in one of the regular jar dependencies
[ERROR] * if the file is present in one of the regular jar dependencies, it should be located in `META-INF/resources/frontend` directory in the jar

有人可以提供一个简单的示例,将“springboot + Vaadin10”应用程序打包为一个带有静态资源的 jar 包吗?

我尝试了这么多配置(将css放在META-INF中,在maven构建过程中包含webapp资源......)但是2天后,我仍然无法在服务器上部署我的应用程序!

【问题讨论】:

    标签: maven spring-boot vaadin10


    【解决方案1】:

    终于解决了

    css 必须在这里:

    src/main/resources/META-INF/resources/frontend/styles.css
    

    然后声明为:

    @StyleSheet("frontend://styles.css")
    

    【讨论】:

    • 仅供参考,如果您有 .html 文件,它们也需要在此文件夹中。
    【解决方案2】:

    即使我仍然错过了一个例子,这也可能会有所帮助:

    Vaadin 10 对其加载静态资源的方式进行了一些更改, 例如应用程序模板、自定义样式和任何其他 JavaScript 文件。它的要点是这些文件应该放在 src/main/webapp/frontend/ 构建 .war 文件时 src/main/resources/META-INF/resources/frontend/ 构建 .jar 时 文件。

    Vaadin 文档链接:Vaadin 10 and static resources

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 2018-03-15
      相关资源
      最近更新 更多