views:

588

answers:

2

Hi,

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.

+2  A: 

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

pmf
Great! This works! And it does not need jetty's DefaultServlet but works fine with HttpServlet.Many thanks!
konrad
A: 

Thank you very much, I was looking for this!

Michal Hantl