| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
JRuby-Rack is a lightweight adapter for the Java Servlet environment that allows any (Ruby) Rack-based application to run unmodified in a Java Servlet container. JRuby-Rack supports Rails as well as any Rack-compatible Ruby web framework.
For more information on Rack, visit http://rack.github.io/.
| JRuby-Rack Series | Status | Rack | JRuby | Java | Rails | Target Servlet API | Notes |
|---|---|---|---|---|---|---|---|
| 2.0 (planned, unreleased) | Dev | 2.2 | 9.4 → 10.1 | 21+ | 7.2 → 8.0 | 5.0+ (Jakarta EE 9) | ❌ Servlet < 5.0 containers will not work |
| 1.3 (master, unreleased) | Dev | 2.2 | 9.4 → 10.1 | 21+ | 7.2 → 8.0 | 4.0 (Java EE 8) | ✅ Unofficial: Servlet 2.5 → 3.1 & Rails 6.1 → 7.1 also likely OK |
| 1.2 | Maintained | 2.2 | 9.3 → 10.1 | 8+ | 5.0 → 8.0 | 3.0 (Java EE 6) | ✅ Unofficial: Servlet 3.1 → 4.0 also OK with most containers |
| 1.1 | EOL @ 2024-05 | 1.x → 2.2 | 1.6 → 9.4 | 6+ | 2.1 → 5.2 | 2.5 (Java EE 5) | ✅ Unofficial: Servlet 3.0 → 4.0 also OK with most containers |
| 1.0 | EOL @ 2011-11 | 0.9 → 1.x | 1.1 → 1.9 | 5+ | 2.1 → 3.x | 2.5 (Java EE 5) |
The most-common way to use JRuby-Rack with a Java server is to get Warbler.
Warbler depends on the latest version of JRuby-Rack and ensures it gets placed in your WAR file when it gets built.
If you're assembling your own WAR using other means, you can install the jruby-rack gem. It provides a method to locate the jar file:
require 'jruby-rack'
FileUtils.cp JRubyJars.jruby_rack_jar_path, '.'Otherwise you'll need to download the latest jar release, drop it into the WEB-INF/lib directory and configure the RackFilter in your application's web.xml (see following examples).
Here's sample web.xml configuration for Rails. Note the environment and min/max runtime parameters. For multi-threaded (a.k.a. threadsafe!) Rails with a single runtime, set min/max both to 1. Otherwise, define the size of the runtime pool as you wish.
<context-param>
<param-name>rails.env</param-name>
<param-value>production</param-value>
</context-param>
<context-param>
<param-name>jruby.min.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>jruby.max.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
<!-- optional filter configuration init-params : -->
<init-param>
<param-name>resetUnhandledResponse</param-name>
<param-value>true</param-value> <!-- true (default), false or buffer -->
</init-param>
<init-param>
<param-name>addsHtmlToPathInfo</param-name>
<param-value>true</param-value> <!-- true (default), false -->
</init-param>
<init-param>
<param-name>verifiesHtmlResource</param-name>
<param-value>false</param-value> <!-- true, false (default) -->
</init-param>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>The main difference when using a non-Rails Rack application is that JRuby-Rack looks for a "rackup" file named config.ru in WEB-INF/config.ru or WEB-INF/*/config.ru. Here's a sample web.xml configuration :
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
<!-- optional filter configuration init-params (@see above) -->
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.RackServletContextListener</listener-class>
</listener>If you don't have a config.ru or don't want to include it in your web app, you can embed it directly in the web.xml as follows (using Sinatra as an example):
<context-param>
<param-name>rackup</param-name>
<param-value>
require 'rubygems'
gem 'sinatra', '~> 1.3'
require './lib/app'
set :run, false
set :environment, :production
run Sinatra::Application
</param-value>
</context-param>Be sure to escape angle-brackets for XML!
JRuby-Rack's main mode of operation is as a filter. This allows requests for static content to pass through and be served by the application server. Dynamic requests only happen for URLs that don't have a corresponding file, much like many Ruby/Rack applications expect. The (default) filter we recommend using is org.jruby.rack.RackFilter, the filter supports the following (optional) init-params:
The application can also be configured to dispatch through a servlet instead of a filter, the servlet class name is org.jruby.rack.RackServlet.
Several aspects of Rails are automatically set up for you.
JRuby runtime management and pooling is done automatically by the framework. For Rack-only applications (and Rails ones from jruby-rack >= 1.3), a single shared runtime is created and shared for every request by default.
If jruby.min.runtimes and jruby.max.runtimes values are specified pooling of runtimes can be enabled for both types of applications.
We do recommend to boot your runtimes up-front to avoid the cost of initializing one while a request kicks in and find the pool empty, this can be easily avoided by setting jruby.min.runtimes equal to jruby.max.runtimes. You might also want to consider tuning the jruby.runtime.acquire.timeout parameter to not wait too long when all (max) runtimes from the pool are busy.
JRuby-Rack can be configured by setting these key value pairs either as context init parameters in web.xml or as VM-wide system properties.
There are often cases where you need to perform custom initialization of the Ruby environment before booting the application. You can create a file called META-INF/init.rb or WEB-INF/init.rb inside the war file for this purpose. These files, if found, will be evaluated before booting the Rack environment, allowing you to set environment variables, load scripts, etc.
For plain Rack applications, JRuby-Rack also supports a magic comment to solve the "rackup" chicken-egg problem (you need Rack's builder loaded before loading the config.ru, yet you may want to setup the gem version from within the rackup file). As we ship with the Rack gem bundled, otherwise when executing the provided config.ru the bundled (latest) version of Rack will get loaded.
Use rack.version to specify the Rack gem version to be loaded before rackup :
# encoding: UTF-8
# rack.version: ~>2.2.10 (before code is loaded gem '~>2.2.10' will be called)Or the equivalent of doing bundle exec rackup ... if you're using Bundler :
# rack.version: bundler (requires 'bundler/setup' before loading the script)JRuby-Rack sets up a delegate logger for Rails that sends logging output to javax.servlet.ServletContext#log by default. If you wish to use a different logging system, configure jruby.rack.logging as follows:
For those loggers that require a specific named logger, set it with the jruby.rack.logging.name option, by default "jruby.rack" name will be used.
Some example demo applications are available at ./examples.
Checkout the JRuby-Rack code using git :
git clone git@github.com:jruby/jruby-rack.git
cd jruby-rackEnsure you have a compatible JVM installed. It is required for building and compiling.
Build the .jar using Maven :
./mvnw installthe generated jar should be located at target/jruby-rack-*.jar
Alternatively use Rake, e.g. to build the gem (skipping specs) :
rake clean gem SKIP_SPECS=trueYou can not use JRuby-Rack with Bundler directly from the git (or http) URL (gem 'jruby-rack', :github => 'jruby/jruby-rack') since the included .jar file is compiled and generated on-demand during the build (it would require us to package and push the .jar every time a commit changes a source file).
JRuby-Rack is always compiled against the version defined by jruby.compat.version in pom.xml. By default, tests will be run with this default version.
Run tests against a specific JRuby version:
./mvnw test -Djruby.test.version=10.1.1.0Or via JRuby/Rake with the local JRuby version implied by your path:
bundle install
rake specFilter for specific specs:
SPEC=src/spec/ruby/rack/application_spec.rb ./mvnw test
# or
SPEC=src/spec/ruby/rack/application_spec.rb rake specJRuby-Rack defaults to run specs with a Rails stub. You can run the specs against a real Rails version using the Gemfiles managed by the Appraisals gem.
export BUNDLE_GEMFILE=gemfiles/rails72_rack22.gemfile
bundle install
bundle exec rake specVERSION=rails72
cd src/spec/stub
rm -rf $VERSION && BUNDLE_GEMFILE=~/Projects/community/jruby-rack/gemfiles/${VERSION}_rack22.gemfile bundle exec rails new $VERSION --minimal --skip-git --skip-docker --skip-active-model --skip-active-record --skip-test --skip-system-test --skip-dev-gems --skip-bundle --skip-keeps --skip-asset-pipeline --skip-ci --skip-brakeman --skip-rubocopReleasing must be done by users authorized to push to the org.jruby group ID on https://central.sonatype.org and to push the jruby-rack gem to https://rubygems.org.
Please use github to file bugs, patches and/or pull requests. More information at the wiki or ask us on our Matrix room at #jruby:matrix.org.
| Back | FazBrowse Home | New Git URL |