Question

I would like to serve servlets and static content with jetty embedded in JRuby. I tried this:

server = Server.new(8080)
context = Context.new(server, '/', 0)

context_static = Context.new(server, '/static', 0)
context_static.setHandler(ResourceHandler.new)
context_static.setResourceBase('./')
context_static.setContextPath('/static')

servlet = Servlet.new()
holder = ServletHolder.new(servlet)
context.addServlet(holder, '/')
server.start()

The problem is that the http://localhost:8080/static does not work as exepecte but also shows the content created by the servlet and not the static content.

Regarding the servlet: I first used javax.servlet.http.HttpServlet but then switched to org.mortbay.jetty.servlet.DefaultServlet as that one seems to make the parallel serving possible. I would be greatful for any hints to solve this issue.

Was it helpful?

Solution

Try initializing context_static before context (since the constructors take a server argument, I assume the order of instantiation affects the chaining order of the contexts). (Tried it using Jetty 6 and Clojure.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top