Vaadin Spring-Boot app will not render CSS when run as JAR in production mode
Asked Answered
H

0

6

Any thoughts on why when releasing a new Vaadin / Spring-Boot app in production, Vaadin will not render the custom css in frontend directory although it does in debug mode?

The app is built for production as follows:

mvn install -Pproduction

and then ran the resultant app as follows:

java --enable-preview -jar target\app-1.0-SNAPSHOT.jar

When running via JAR file method, the css is not applied correctly in the browser. Everything else works fine.

When the app is run as follows:

mvn spring-boot:run 

All pages are rendered correctly. The css is loaded correctly.

In the LoginView class, the CSS is imported as follows:

@CssImport(value = "./views/login/login-view.css", themeFor = "vaadin-login-overlay-wrapper")

The login-view.css file is located in [project dir]\frontend\views\login-view.css

When running mvn spring-boot:run, the CSS file is picked up correctly, however, when running using the JAR method, it is not. I'm not sure if this is by design or not but I dont see the css files stored anywhere in the resultant JAR file.

To mitigate this, I tried putting the frontend files, inside [project dir]\src\main\resources\META-INF\frontend instead of the default location [project dir]\frontend because I read somewhere that CssImport looks inside the resources\META-INF\frontend folder when running via a JAR. When I put the files in this location, the CSS files are incorporated in the JAR and accessible from http://localhost:8080/frontend/views/login/login-view.css, but alas the LoginView page still doesn't seem to render the CSS.

The app was originally built using the Vaadin app builder. The pom.xml is largely the same as the default one. I'm running Vaadin 19.0.7. Thanks in advance

Hygiene answered 21/7, 2021 at 7:51 Comment(6)
Are the styles not correct or are you just lookin for the CSS file? Because all the CSS and JS from frontend will be bundled together.Skerl
Thanks for reply. The CSS styles are correct, and are showing correctly when the server is run in debug mode. However, when server is run production, the css is not rendered at all.Hygiene
Can you please provide a minimal reproducible example? Because with may project everything works fineSkerl
I am also observing same issue in vaadin 20.0.6. Did you find any solution for this?Unremitting
Unfortunately, I did not. For now, we are running in straight (without JAR packaging). If find a resolution, I'd appreciate if you could post below.Hygiene
The correct folder in jar for frontend reources is \src\main\resources\META-INF\resources\frontendJuror

© 2022 - 2024 — McMap. All rights reserved.