Favicon missing from runnable jar

Hi,

If you just check out the vaadin flow spring starter, you build the jar file, and run it with java -jar, the favicon is missing.
The question is what to do, how to properly configure the project to have the favicon.

Best regards, thanks!

Hi Marton,

I haven’t looked at the flow starter for a while. Assuming that it already includes a favicon, or you added it yourself, make sure it’s in the right location.

This blog entry details where static content needs to go in war vs. jar.

https://vaadin.com/blog/vaadin-10-and-static-resources

Also check that you have a BootstrapListener that references it:

public class CustomBootstrapListener implements BootstrapListener {
   @Override
   public void modifyBootstrapPage(BootstrapPageResponse response) {

      final Element head = response.getDocument().head();

      // manifest needs to be prepended before scripts or it won't be loaded
      head.prepend("<meta name='theme-color' content='#227aef'>");
      head.prepend("<link rel='manifest' href='manifest.json'>");

      // Add service worker
      head.append("<script>if ('serviceWorker' in navigator) navigator.serviceWorker.register('sw.js')</script>");

      // add icons tags
      head.append("<link rel='shortcut icon' href='icons/favicon.ico'>");
      head.append("<link rel='icon' sizes='192x192' href='icons/icon-192.png'>");
      head.append("<link rel='icon' sizes='96x96' href='icons/icon-96.png'>");
      head.append("<link rel='apple-touch-icon' sizes='192x192' href='icons/icon-192.png'>");
      head.append("<link rel='apple-touch-icon' sizes='96x96' href='icons/icon-96.png'>");
   }
}

Also make sure that your security configuration allows the icon to be retrieved.

Hi Marton,

THank you for the answer, the only strange thing is that:

If I start with spring-boot:run, so it runs the exploded contents, then the favicon is there.
If I use the jarfile, then it is not, I thought there should be no need for a bootstrap listener, but I will try.

Thank you!

In that case it’s probably not the bootstrap listener, but it could be a package issue.

Check out
https://vaadin.com/blog/vaadin-10-and-static-resources
and
https://vaadin.com/forum/thread/16988003/vaadin-10-with-spring-boot-packages-as-jar

Ok, so the solution is simply to add this, somehow it works from war and exploded without this setting, but from jar it does not…

@Override
public void configurePage(InitialPageSettings settings) {
settings.addLink(“shortcut icon”, “icons/favicon.ico”);
settings.addFavIcon(“icon”, “icons/icon.png”, “256x256”);
}

Marton Szabo:
Ok, so the solution is simply to add this, somehow it works from war and exploded without this setting, but from jar it does not…

@Override
public void configurePage(InitialPageSettings settings) {
settings.addLink(“shortcut icon”, “icons/favicon.ico”);
settings.addFavIcon(“icon”, “icons/icon.png”, “256x256”);
}

hi, I found some issue with configurePage above. In case that, I used annotation @PreserveOnRefresh on those views then after a few refresh on that view, favicon isn’t load or gone away. Please help me. Thank in advanced.