vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

Favicon not shown with JAR packaging #8705

Closed alejandro-du closed 4 years ago

alejandro-du commented 4 years ago

Description of the bug

When packaging a project as a JAR, using a custom icon.png in src/main/resources/META-INF/resources/icons, and running with java -jar ..., the custom favicon is not shown (it is shown correctly when running the main method in IntelliJ IDEA, though). The problem is the same with both development and production builds.

Minimal reproducible example

Go to https://vaadin.com/start/v14. Create a Spring Boot project. Replace the icon.png file with a custom one. Build with mvn package. Run with ´java -jar ...`.

Expected behavior

Should show the custom icon.

Actual behavior

Shows the default white circle with a blue background icon.

Versions:

- Vaadin / Flow version: 14.3.0
- Java version: 8 and 11
- OS version: macOS
- Browser version (if applicable): Chrome
denis-anisimov commented 4 years ago

In fact it's even worse: no need to replace the existing icon at all. The provided icon in the skeleton src/main/resources/META-INF/resources/icons/icon.png is shown being run via spring-boot:run but a default icon ( totally different one) is shown being run via java -jar.

denis-anisimov commented 4 years ago

This is a Spring issue. The problem is that all classes being packaged in Jar goes into BOOT-INF folder. But resources goes to META-INF directly (not as a sub-package of BOOT-INF).

Then embedded servlet container is responsible for finding the resources (as static web resources). By default Tomcat is used . TomcatServletWebServerFactory has code in its nested StaticResourceConfigurer which scans Jars for "/META-INF/resources" folders. But that works only for Jars inside the Jar (library Jars) and the "/META-INF" inside the Jar itself is not handled.

So as a result: the code in Flow tries to search the static web resource using a Servlet context and it's not able to find it (see above). The proper way to fix this would be fix the project itself specifically for this case since Spring is not able to handle this properly. So it should be fixed in skeleton-starter project itself.

I'm going to implement a workaround as well in Flow for this specific case: search the resource in classpath if it's not found via a servlet context. But this is more a hack (and it's not really correct to fix this Spring specific case in Flow repo).

denis-anisimov commented 4 years ago

A workaround in Flow : https://github.com/vaadin/flow/pull/8808 A proper fix in skeleton: https://github.com/vaadin/skeleton-starter-flow-spring/pull/381

Artur- commented 4 years ago

Another way to solve this would be to use the approach prototyped in https://github.com/vaadin/flow/tree/webpack-workbox to enable offline routing using the webpack workbox plugin

It moves all @PWA, manifest, sw.js and icon handling to the build phase instead of runtime.

nox10 commented 2 years ago

In Vaadin 22.0.5 it's not working again (in Vaadin 14 everything is ok though)

nox10 commented 2 years ago

This is because the default icon now is in resources as well, from exampledata-4.1.0.jar dependency, which eventually breaks the workaround #8808.

I used truezip-maven-plugin to remove the default icon from exampledata-4.1.0.jar archive during package step, as another temporary workaround for this situation.

Artur- commented 2 years ago

Exampledata has been fixed in 4.1.1

nox10 commented 2 years ago

Thank you