Skip to content

Instantly share code, notes, and snippets.

@glejeune
Forked from hakunin/gist:188015
Created January 27, 2010 07:28
Show Gist options
  • Save glejeune/287629 to your computer and use it in GitHub Desktop.
Save glejeune/287629 to your computer and use it in GitHub Desktop.
require 'java'
require 'rubygems'
rb_root = File.dirname(__FILE__)
app_root = File.dirname(__FILE__)+'/..'
Dir[app_root+"/*.jar"].each { |jar| require jar }
require 'rack'
Dir[app_root+"/Java/jetty/*.jar"].each { |jar| require jar }
Dir[app_root+"/Java/jsdk/*.jar"].each { |jar| require jar }
include_class 'javax.servlet.http.HttpServlet'
include_class 'org.mortbay.jetty.Server'
include_class 'org.mortbay.jetty.servlet.Context'
include_class 'org.mortbay.jetty.servlet.ServletHolder'
include_class 'org.mortbay.jetty.servlet.DefaultServlet'
include_class 'org.jruby.rack.servlet.ServletRackContext'
include_class 'org.mortbay.jetty.handler.ResourceHandler'
include_class 'org.mortbay.jetty.handler.DefaultHandler'
include_class 'org.mortbay.jetty.handler.HandlerList'
include_class 'org.mortbay.jetty.Handler'
include_class 'org.mortbay.jetty.handler.ResourceHandler'
include_class 'org.mortbay.jetty.handler.ContextHandlerCollection'
include_class 'org.mortbay.jetty.servlet.DefaultServlet'
include_class 'org.jruby.rack.RackServletContextListener'
server = Server.new(80)
c = Context.new(nil, "/", Context::NO_SESSIONS)
c.add_filter("org.jruby.rack.RackFilter", "/*", Handler::DEFAULT)
c.set_resource_base(File.dirname(__FILE__))
c.add_event_listener(RackServletContextListener.new)
rackup = "
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Static, :urls => ['/public'], :root => '#{app_root}/'
run lambda { |env|
[200, {},
'<h1>Hello From JRuby Rack!</h1>'+
Time.now.to_s+
'<br>env:'+env.inspect
]
}
"
c.set_init_params(java.util.HashMap.new(
'public.root' => app_root+'/public',
'org.mortbay.jetty.servlet.Default.relativeResourceBase' => '/public',
'rackup' => rackup,
'jruby.max.runtimes' => '1'))
c.add_servlet(ServletHolder.new(DefaultServlet.new), "/*")
server.set_handler(c)
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment