Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:44:58+00:00 2026-06-04T16:44:58+00:00

Similar to another question (cf. Filtering static content Jersey ) I want to serve

  • 0

Similar to another question (cf. Filtering static content Jersey) I want to serve static content from Jetty. There are several similar questions scattered all around the vast Internet, but most of them do not involve Guice, and those that do are completely out of date.

I have an existing service that uses Jersey (1.12) and Guice (3) with the following web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <display-name>My Service</display-name>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <listener>
        <listener-class>com.example.MyGuiceConfig</listener-class>
    </listener>

    <filter>
        <filter-name>Guice Filter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Guice Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

MyGuiceConfig looks like so:

public class MyGuiceConfig extends GuiceServletContextListener
{
    @Override
    protected Injector getInjector()
    {
        return Guice.createInjector(new JerseyServletModule()
        {
            @Override
            protected void configureServlets()
            {
                bind(SomeResource.class);
                bind(SomeDao.class).to(ConcreteSomeDao.class);
                serve("/*").with(GuiceContainer.class);
            }
        });
    }
}

When I invoke the jetty-maven-plugin using mvn jetty:run, my service works as expected. But, any request to static content produces a 404.

How can I serve arbitrary static content without affecting my service? (i.e. The minimal change necessary that doesn’t require me to change my tech stack?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:45:00+00:00Added an answer on June 4, 2026 at 4:45 pm

    How have you configured the url fragment that Jersey will handle in your JerseyServletModule? If you specify a prefix that doesn’t conflict with your static content it should work.

    public class Config extends GuiceServletContextListener {
    
      protected Injector getInjector() {
        return Guice.createInjector(
            new JerseyServletModule() {
              protected void configureServlets() {
                bind(Service.class);
                serve("/services/*").with(GuiceContainer.class);
              }
            });
      }
    
    }
    

    and

    @Singleton
    @Path("/service")
    @Produces({MediaType.TEXT_PLAIN})
    public class Service {
    
      @GET
      public String run() {
        return "Service running";
      }
    
    }
    

    should serve Servlet.class from host:8080/services/service and static resources that are included in the webapp…

    EDIT See Jersey /* servlet mapping causes 404 error for static resources for another way to accomplish this without changing the path of your REST endpoint.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found another similar question: Best way to download images from XML content in
There is another similar question to mine, but the discussion veered away from the
I know there is another question that exists similar to this one but I
This is similar to another question (http://stackoverflow.com/questions/935556/mysql-dump-by-query) but I hope different enough. I want
I'm aware that there is another similar question on this topic, but personally I
Okay, so there's another similar question that I found to this on SO but
After reading this question , I have another similar question. Is there a simple
I saw another similar question answered here - Velocity editor plugin for Eclipse? .
Note: I had another similar question about how to GZIP data using Ruby's zlib
This is very similar to another recent question: How can I return the current

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.