Skip to content
Browse files

support for static (non-erb) config/web.xml and public/WEB-INF

  • Loading branch information...
1 parent ede415a commit 95abc3c213e88c420a57acc2b621e2fcd7b32692 @fabiokung committed Dec 2, 2008
Showing with 22 additions and 6 deletions.
  1. +21 −6 lib/jetty_rails/handler/web_app_handler.rb
  2. +1 −0 lib/jetty_rails/jars.rb
View
27 lib/jetty_rails/handler/web_app_handler.rb
@@ -8,20 +8,22 @@ def initialize(config)
@config = config
self.class_loader = each_context_has_its_own_classloader
- self.resource_base = config[:base]
+ self.resource_base = "#{config[:base]}/public"
self.descriptor = config[:web_xml]
add_classes_dir_to_classpath(config)
add_lib_dir_jars_to_classpath(config)
-
+
@adapter = adapter_for(config[:adapter])
self.init_params = @adapter.init_params
- @adapter.event_listeners.each do |listener|
- add_event_listener(listener)
- end
+ unless File.exist?(self.descriptor)
+ @adapter.event_listeners.each do |listener|
+ add_event_listener(listener)
+ end
- add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
+ add_filter(rack_filter, "/*", Jetty::Context::DEFAULT)
+ end
end
def self.add_adapter(adapter_key, adapter)
@@ -38,6 +40,13 @@ def self.adapters
def adapters
self.class.adapters
end
+
+ alias :get_from_public_otherwise :getResource
+
+ def getResource(resource)
+ return fix_for_base_url if resource == '/'
+ get_from_public_otherwise resource
+ end
protected
def rack_filter
@@ -49,18 +58,24 @@ def adapter_for(kind)
end
private
+ def fix_for_base_url
+ Jetty::FileResource.new(java.io.File.new(config[:base]).to_url)
+ end
+
def add_lib_dir_jars_to_classpath(config)
lib_dir = "#{config[:base]}/#{config[:lib_dir]}/**/*.jar"
Dir[lib_dir].each do |jar|
url = java.io.File.new(jar).to_url
self.class_loader.add_url(url)
end
end
+
def add_classes_dir_to_classpath(config)
classes_dir = "#{config[:base]}/#{config[:classes_dir]}"
url = java.io.File.new(classes_dir).to_url
self.class_loader.add_url(url)
end
+
def each_context_has_its_own_classloader()
org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
end
View
1 lib/jetty_rails/jars.rb
@@ -11,6 +11,7 @@ module Jetty
include_package "org.mortbay.jetty"
include_package "org.mortbay.jetty.servlet"
include_package "org.mortbay.jetty.nio"
+ include_package "org.mortbay.resource"
module Handler
include_package "org.mortbay.jetty.handler"
include_package "org.mortbay.jetty.webapp"

0 comments on commit 95abc3c

Please sign in to comment.
Something went wrong with that request. Please try again.