Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favicon not shown with JAR packaging #8705

Closed
alejandro-du opened this issue Jul 8, 2020 · 8 comments · Fixed by #8808
Closed

Favicon not shown with JAR packaging #8705

alejandro-du opened this issue Jul 8, 2020 · 8 comments · Fixed by #8808

Comments

@alejandro-du
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

A workaround in Flow : #8808
A proper fix in skeleton: vaadin/skeleton-starter-flow-spring#381

@Artur-
Copy link
Member

Artur- commented Aug 4, 2020

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.

mshabarov pushed a commit that referenced this issue Aug 6, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments
mshabarov pushed a commit that referenced this issue Aug 12, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments

(cherry picked from commit 6f1d6a5)
mshabarov pushed a commit that referenced this issue Aug 13, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments

(cherry picked from commit 6f1d6a5)
mshabarov pushed a commit that referenced this issue Aug 13, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments

(cherry picked from commit 6f1d6a5)
caalador pushed a commit that referenced this issue Aug 20, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments

(cherry picked from commit 6f1d6a5)
haijian-vaadin pushed a commit that referenced this issue Aug 24, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments
mshabarov pushed a commit that referenced this issue Aug 24, 2020
* Make a workaround for Spring boot run as jar

Fixes #8705

* Add a unit test for implemented workaround.

* Add forgotten resource

* Improve variable name and add comments
@nox10
Copy link

nox10 commented Feb 20, 2022

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

@nox10
Copy link

nox10 commented Feb 21, 2022

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-
Copy link
Member

Artur- commented Feb 21, 2022

Exampledata has been fixed in 4.1.1

@nox10
Copy link

nox10 commented Feb 21, 2022

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants