Jetty Rails
Get Version
0.8.1→ ‘jetty-rails’
What
See the what is included in the last version.
Jetty Rails aims to run Ruby on Rails and Merb applications with the Jetty Container, leveraging the power of JRuby and jruby-rack.
Jetty is an excellent Java Web Server, being and at the same time extremely lightweight. This makes jetty-rails a good alternative for JRuby on Rails or Merb development and deployment.
The project has born from my own needs (read more). I needed to run JForum on the same context of my jruby on rails application. I had also to integrate HttpSessions
(avoiding single sign on) and use ServletContext
in-memory cache store.
Installing
jruby -S gem install jetty-rails
The basics
Jetty Rails uses Jetty Handlers to dispatch requests to the JRuby Rack adapter.
All extra jars inside your application lib/ dir will be loaded. Things like Java HttpSession
, ServletContext
and Runtime Pools are given by JRuby Rack Filter.
Additionally, Jetty Rails automatically puts classes inside the classes/ dir
in the application classpath, so you can use them in your rails code.
Demonstration of usage
Rails:
cd myrailsapp
jruby -S jetty_rails
Merb:
cd mymerbapp
jruby -S jetty_merb
—help option shows usage details:
jruby -S jetty_rails --help
jruby -S jetty_merb --help
Please note that you may only use Merb with ActiveRecord, as DataMapper doesn’t work in JRuby yet.
Multiple Servers
You can specify a configuration yaml file rather than command line switches.
The file also allows specifying multiple servers and / or application contexts for single jetty container. Jetty Documentation
For example, you could set a context_path of /testA on port 8888 which is rails, /testB also that port which is merb.
Or, you could have /testA on port 8888 and /testB on port 9999.
jruby -S jetty_rails -c path/to/config.yml
The configuration options are inherited, so if you specify the environment to be “production” at the top level,
then any servers and application context will be “production” unless the choose to override the value.
- server settings:
:port :jruby_min_runtimes :jruby_max_runtimes :thread_pool_max :thread_pool_min :acceptor_size
- application context settings:
:context_path :base :adapter :environment :lib_dir :gem_path
As part of the configuration you have some control over jruby & jetty. Take a look at one complete config.yml from the examples bundled in jetty-rails:
--- :servers: - :context_path: /testA :base: jetty_rails_proj_2 :adapter: :rails :environment: development :port: 2000 - :context_path: /testB :adapter: :rails :base: jetty_rails_proj :environment: production :port: 3000 - :port: 4000 :apps: - :context_path: /testB :adapter: :rails :base: jetty_rails_proj :environment: development - :context_path: /testA :adapter: :rails :base: jetty_rails_proj_2 :environment: production :environment: production :jruby_min_runtimes: 1 :jruby_max_runtimes: 2 :thread_pool_max: 40 :thread_pool_min: 1 :acceptor_size: 20
For more examples see:
- spec/config.yml
- spec/jetty_rails_sample_1.yml
- spec/jetty_rails_sample_2.yml
Rails:
If -c is not specified, by default jetty_rails will look for a config/jetty_rails.yml
relative to where it is started.
Don’t forget to add this into your config/environment.rb
ActionController::AbstractRequest.relative_url_root = “/testA”
JRuby Configuration
You can tweak the JRuby runtimes per application context:
:jruby_min_runtimes: 1 :jruby_max_runtimes: 2
Jetty Configuration
You can also modify the jetty per server configurations.
Thread pool will define the thread pool available to the jetty server using a QueuedThreadPool
.
:thread_pool_max: 40 :thread_pool_min: 1
The acceptor size is the number of acceptor threads available for that server’s channel connector.
:acceptor_size: 20
See the jetty documentation for more information.
More Documentation
See RDoc
Mailing list
groups.google.com/group/jetty-rails
Bug Tracking and New Features
Using Lighthouse: fabiokung.lighthouseapp.com/projects/12666-jetty-rails
Getting the source
github: github.com/fabiokung/jetty-rails/tree/master
git clone git://github.com/fabiokung/jetty-rails.git
Build and test instructions
cd jetty-rails jruby -S rake # run specs jruby -S rake package jruby -S gem install pkg/*.gem
License
Jetty Rails is distributed under the terms of The MIT License.
Copyright © 2008 Fabio Kung
Read more details in the bundled Licenses.txt file. There are other pieces of software bundled with jetty-rails. Before using jetty-rails, make sure you agree with all of them.
Contact
Comments are welcome. Send an email to Fabio Kung via the mailing list
Fabio Kung, 24th June 2009
Theme extended from Paul Battley