1

The question is simple, but I spent the last 2 days trying to deploy my app. And so far it doesn't.

I have a single CSS file for my style, and when I execute the jar, CSS is not found (404) or the jar won't package.

As stated here: Spring Boot Executable jar structure "Do not use the src/main/webapp folder if your application will be packaged as a jar" and "You should place your static resources in src/main/resources instead."

so put the CSS here: src/main/resources/styles.css

In Vaadin documentation (which is very pour on how to package...) I import the CSS like this:

@StyleSheet("styles.css")

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

Then I package my project:

 mvn clean package -Pproduction

I get this error:

[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

Can someone provide a simple example of a 'springboot + Vaadin10' app packaged as a jar with static resources inside ?

I tried so many configurations (put the CSS in META-INF, include webapp resources in the maven build process...) but after 2 days, I still can't deploy my app on the server!

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Tyvain
  • 2,640
  • 6
  • 36
  • 70

2 Answers2

2

finally the solution

css has to be here:

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

then declared as:

@StyleSheet("frontend://styles.css")
Tyvain
  • 2,640
  • 6
  • 36
  • 70
1

This could be helpful too even though I still miss an example:

Vaadin 10 makes some changes to the way it loads static resources, such as application templates, custom styles and any additional JavaScript files. The gist of it is that such files should be put in src/main/webapp/frontend/ when building a .war file and src/main/resources/META-INF/resources/frontend/ when building a .jar file.

Link to Vaadin Dokumentation: Vaadin 10 and static resources

the hand of NOD
  • 1,639
  • 1
  • 18
  • 30