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?)