Search code examples
javajettyfavicon

Embedded Jetty and favicon


I am using Jetty embedded in my application as follows:

    ResourceConfig rc = new PackagesResourceConfig("my.jersey.resources.package");
    ServletHolder servletHolder = new ServletHolder(new ServletContainer(rc));
    ServletContextHandler servletContextHandler =
            new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    servletContextHandler.addServlet(servletHolder, "/" + customContextPath + "/*");
    server.start();

Is there any way for me to add some kind of handling for a custom favicon.ico using the aforementioned setup?

Thanks


Solution

  • Just adding the favicon.ico to the root directory doesn't work because the browser doesn't include the app's context when fetching the favicon. Add this to your HTML:

    <link rel="shortcut icon" href="images/favicon.ico">
    

    Be sure to provide a correct absolute or relative path to your favicon.