{"id":18909120,"url":"https://github.com/jruby/jruby-rack","last_synced_at":"2025-05-14T21:10:02.408Z","repository":{"id":398513,"uuid":"16667","full_name":"jruby/jruby-rack","owner":"jruby","description":"Rack for JRuby and Java appservers","archived":false,"fork":false,"pushed_at":"2025-04-02T08:42:55.000Z","size":7479,"stargazers_count":399,"open_issues_count":15,"forks_count":137,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-13T17:46:58.025Z","etag":null,"topics":["deployment","jruby","jruby-rack","rack-application","rack-environment","servlets","tomcat","warbler"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":"Unmaintained","scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jruby.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2008-05-14T02:57:24.000Z","updated_at":"2025-04-02T08:43:02.000Z","dependencies_parsed_at":"2024-05-23T04:41:43.920Z","dependency_job_id":"5bbf4363-d34c-46e2-9a9b-3f452add4e6a","html_url":"https://github.com/jruby/jruby-rack","commit_stats":{"total_commits":1135,"total_committers":48,"mean_commits":"23.645833333333332","dds":0.5911894273127754,"last_synced_commit":"710c1a4cbde684f1d0bec5907ba3071d51de0a96"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-rack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-rack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-rack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-rack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jruby","download_url":"https://codeload.github.com/jruby/jruby-rack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227631,"owners_count":22035671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","jruby","jruby-rack","rack-application","rack-environment","servlets","tomcat","warbler"],"created_at":"2024-11-08T09:31:04.976Z","updated_at":"2025-05-14T21:10:01.297Z","avatar_url":"https://github.com/jruby.png","language":"Ruby","readme":"# JRuby-Rack\n\nJRuby-Rack is a lightweight adapter for the Java Servlet environment that allows\nany (Ruby) Rack-based application to run unmodified in a Java Servlet container.\nJRuby-Rack supports Rails as well as any Rack-compatible Ruby web framework.\n\nFor more information on Rack, visit http://rack.github.io/.\n\n**This README (master) targets JRuby-Rack 1.2. Please use the\n[1.1-stable](https://github.com/jruby/jruby-rack/tree/1.1-stable) branch for\ncurrent stable 1.1.x releases.**\n\n[![Gem Version](https://badge.fury.io/rb/jruby-rack.png)][8]\n[![Build Status](https://github.com/jruby/jruby-rack/actions/workflows/maven.yml/badge.svg)][9]\n\n## Compatibility\n\nJRuby-Rack 1.2.x\n- aims to be compatible with JRuby \u003e= 9.3 and its supported JDK versions\n- supports any container compatible with Java Servlet 3.0 API\n\nJRuby-Rack 1.1.x\n- aims to be compatible with JRuby \u003e= 1.6.4 (used successfully through JRuby 9.4.x)\n- supports any container compatible with Java Servlet 2.5 API (JEE 5)\n\n\n## Getting Started\n\nThe most-common way to use JRuby-Rack with a Java server is to get [Warbler][1].\n\nWarbler depends on the latest version of JRuby-Rack and ensures it gets placed\nin your WAR file when it gets built.\n\nIf you're assembling your own WAR using other means, you can install the\n**jruby-rack** gem. It provides a method to locate the jar file:\n\n    require 'jruby-rack'\n    FileUtils.cp JRubyJars.jruby_rack_jar_path, '.'\n\nOtherwise you'll need to download the latest [jar release][2], drop it into the\n*WEB-INF/lib* directory and configure the `RackFilter` in your application's\n*web.xml* (see following examples).\n\nAlternatively you can use a server built upon JRuby-Rack such as [Trinidad][3]\nwith sensible defaults, without the need to configure a deployment descriptor.\n\n### Rails\n\nHere's sample *web.xml* configuration for Rails. Note the environment and\nmin/max runtime parameters. For **multi-threaded** (a.k.a. `threadsafe!`)\nRails with a single runtime, set min/max both to 1. Otherwise, define the size\nof the runtime pool as you wish.\n\n    \u003ccontext-param\u003e\n      \u003cparam-name\u003erails.env\u003c/param-name\u003e\n      \u003cparam-value\u003eproduction\u003c/param-value\u003e\n    \u003c/context-param\u003e\n    \u003ccontext-param\u003e\n      \u003cparam-name\u003ejruby.min.runtimes\u003c/param-name\u003e\n      \u003cparam-value\u003e1\u003c/param-value\u003e\n    \u003c/context-param\u003e\n    \u003ccontext-param\u003e\n      \u003cparam-name\u003ejruby.max.runtimes\u003c/param-name\u003e\n      \u003cparam-value\u003e1\u003c/param-value\u003e\n    \u003c/context-param\u003e\n\n    \u003cfilter\u003e\n      \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n      \u003cfilter-class\u003eorg.jruby.rack.RackFilter\u003c/filter-class\u003e\n      \u003c!-- optional filter configuration init-params : --\u003e\n      \u003cinit-param\u003e\n        \u003cparam-name\u003eresetUnhandledResponse\u003c/param-name\u003e\n        \u003cparam-value\u003etrue\u003c/param-value\u003e \u003c!-- true (default), false or buffer --\u003e\n      \u003c/init-param\u003e\n      \u003cinit-param\u003e\n        \u003cparam-name\u003eaddsHtmlToPathInfo\u003c/param-name\u003e\n        \u003cparam-value\u003etrue\u003c/param-value\u003e \u003c!-- true (default), false --\u003e\n      \u003c/init-param\u003e\n      \u003cinit-param\u003e\n        \u003cparam-name\u003everifiesHtmlResource\u003c/param-name\u003e\n        \u003cparam-value\u003efalse\u003c/param-value\u003e \u003c!-- true, false (default) --\u003e\n      \u003c/init-param\u003e\n    \u003c/filter\u003e\n    \u003cfilter-mapping\u003e\n      \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n      \u003curl-pattern\u003e/*\u003c/url-pattern\u003e\n    \u003c/filter-mapping\u003e\n\n    \u003clistener\u003e\n      \u003clistener-class\u003eorg.jruby.rack.rails.RailsServletContextListener\u003c/listener-class\u003e\n    \u003c/listener\u003e\n\n### (Other) Rack Applications\n\nThe main difference when using a non-Rails Rack application is that JRuby-Rack\nlooks for a \"rackup\" file named **config.ru** in  `WEB-INF/config.ru` or\n`WEB-INF/*/config.ru`. Here's a sample *web.xml* configuration :\n\n    \u003cfilter\u003e\n      \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n      \u003cfilter-class\u003eorg.jruby.rack.RackFilter\u003c/filter-class\u003e\n      \u003c!-- optional filter configuration init-params (@see above) --\u003e\n    \u003c/filter\u003e\n    \u003cfilter-mapping\u003e\n      \u003cfilter-name\u003eRackFilter\u003c/filter-name\u003e\n      \u003curl-pattern\u003e/*\u003c/url-pattern\u003e\n    \u003c/filter-mapping\u003e\n\n    \u003clistener\u003e\n      \u003clistener-class\u003eorg.jruby.rack.RackServletContextListener\u003c/listener-class\u003e\n    \u003c/listener\u003e\n\nIf you don't have a *config.ru* or don't want to include it in your web app, you\ncan embed it directly in the *web.xml* as follows (using Sinatra as an example):\n\n    \u003ccontext-param\u003e\n      \u003cparam-name\u003erackup\u003c/param-name\u003e\n      \u003cparam-value\u003e\n        require 'rubygems'\n        gem 'sinatra', '~\u0026gt; 1.3'\n        require './lib/app'\n        set :run, false\n        set :environment, :production\n        run Sinatra::Application\n      \u003c/param-value\u003e\n    \u003c/context-param\u003e\n\nBe sure to escape angle-brackets for XML !\n\n\n## Servlet Filter\n\nJRuby-Rack's main mode of operation is as a filter. This allows requests for\nstatic content to pass through and be served by the application server.\nDynamic requests only happen for URLs that don't have a corresponding file, much\nlike many Ruby/Rack applications expect. The (default) filter we recommend\nusing is `org.jruby.rack.RackFilter`, the filter supports the following\n(optional) init-params:\n\n- **responseNotHandledStatuses** which statuses (when a filter chain returns)\n  should be considered that the response has not been handled (default value:\n  \"403,404,405\") and should be dispatched as a Rack application\n- **resetUnhandledResponse** whether an unhandled response from the filter chain\n  gets reset (accepts  values \"true\", \"false\" and \"buffer\" to reset the buffer\n  only), by default \"true\"\n- **addsHtmlToPathInfo** controls whether the .html suffix is added to the URI\n  when checking if the request is for a static page\n- **verifiesHtmlResource** used with the previous parameter to make sure the\n  requested static resource exists before adding the .html request URI suffix\n\nThe application can also be configured to dispatch through a servlet instead of\na filter, the servlet class name is `org.jruby.rack.RackServlet`.\n\n## Servlet Environment Integration\n\n- servlet context is accessible to any application through the Rack environment\n  variable *java.servlet_context* (as well as the `$servlet_context` global).\n- the (native) servlet request and response objects could be obtained via the\n  *java.servlet_request* and *java.servlet_response* keys\n- all servlet request attributes are passed through to the Rack environment (and\n  thus might override request headers or Rack environment variables)\n- servlet sessions can be used as a (java) session store for Rails, session\n  attributes with String keys (and String, numeric, boolean, or java\n  object values) are automatically copied to the servlet session for you.\n\n## Rails\n\nSeveral aspects of Rails are automatically set up for you.\n\n- `ActionController::Base.relative_url_root` is set for you automatically\n  according to the context root where your webapp is deployed.\n- `Rails.logger` output is redirected to the application server log.\n- Page caching and asset directories are configured appropriately.\n\n## JRuby Runtime Management\n\nJRuby runtime management and pooling is done automatically by the framework.\nIn the case of Rails, runtimes are pooled by default (the default will most\nlikely change with the adoption of Rails 4.0). For other Rack applications a\nsingle shared runtime is created and shared for every request by default.\nAs of **1.1.9** if *jruby.min.runtimes* and *jruby.max.runtimes* values are\nspecified pooling is supported for plain Rack applications as well.\n\nWe do recommend to boot your runtimes up-front to avoid the cost of initializing\none while a request kicks in and find the pool empty, this can be easily avoided\nby setting *jruby.min.runtimes* equal to *jruby.max.runtimes*. You might also\nwant to consider tuning the *jruby.runtime.acquire.timeout* parameter to not\nwait too long when all (max) runtimes from the pool are busy.\n\n## JRuby-Rack Configuration\n\nJRuby-Rack can be configured by setting these key value pairs either\nas context init parameters in web.xml or as VM-wide system properties.\n\n- `rackup`: Rackup script for configuring how the Rack application is mounted.\n  Required for Rack-based applications other than Rails. Can be omitted if a\n  *config.ru* is included in the application root.\n- `public.root`: Relative path to the location of your application's static\n  assets. Defaults to */*.\n- `rails.root`: Root path to the location of the Rails application files.\n  Defaults to */WEB-INF*.\n- `rails.env`: Specify the Rails environment to run. Defaults to 'production'.\n- `rails.relative_url_append`: Specify a path to be appended to the\n  `ActionController::Base.relative_url_root` after the context path. Useful\n  for running a rails app from the same war as an existing app, under a\n  sub-path of the main servlet context root.\n- `gem.path`: Relative path to the bundled gem repository. Defaults to\n  */WEB-INF/gems*.\n- `jruby.compat.version`: Set to \"1.8\" or \"1.9\" to make JRuby run a specific\n  version of Ruby (same as the --1.8 / --1.9 command line flags).\n- `jruby.min.runtimes`: For non-threadsafe Rails applications using a runtime\n  pool, specify an integer minimum number of runtimes to hold in the pool.\n- `jruby.max.runtimes`: For non-threadsafe Rails applications, an integer\n  maximum number of runtimes to keep in the pool.\n- `jruby.runtime.init.threads`: How many threads to use for initializing\n   application runtimes when pooling is used (default is 4).\n   It does not make sense to set this value higher than `jruby.max.runtimes`.\n- `jruby.runtime.init.serial`: When using runtime pooling, this flag indicates\n  that the pool should be created serially in the foreground rather than\n  spawning (background) threads, it's by default off (set to false).\n  For environments where creating threads is not permitted.\n- `jruby.runtime.acquire.timeout`: The timeout in seconds (default 10) to use\n  when acquiring a runtime from the pool (while a pool maximum is set), an\n  exception will be thrown if a runtime can not be acquired within this time (\n  accepts decimal values for fine tuning e.g. 1.25).\n- `jruby.runtime.env`: Allows to set a custom ENV hash for your Ruby environment\n  and thus insulate the application from the environment it is running. By setting\n  this option to en empty string (or 'false') it acts as if the ENV hash was\n  cleared out (similar to the now deprecated `jruby.rack.ignore.env` option).\n- `jruby.runtime.env.rubyopt`: This option is used for compatibility with the\n  (deprecated) `jruby.rack.ignore.env` option since it cleared out the ENV after\n  RUBYOPT has been processed, by setting it to true ENV['RUBYOPT'] will be kept.\n- `jruby.rack.logging`: Specify the logging device to use. Defaults to\n  `servlet_context`. See below.\n- `jruby.rack.request.size.initial.bytes`: Initial size for request body memory\n   buffer, see also `jruby.rack.request.size.maximum.bytes` below.\n- `jruby.rack.request.size.maximum.bytes`: The maximum size for the request in\n   memory buffer, if the body is larger than this it gets spooled to a tempfile.\n- `jruby.rack.response.dechunk`: Set to false to turn off response dechunking\n  (Rails since 3.1 chunks response on `render stream: true`), it's on by default\n  as frameworks such as Rails might use `Rack::Chunked::Body` as a Rack response\n  body but since most servlet containers perform dechunking automatically things\n  might end double-chunked in such cases.\n- `jruby.rack.handler.env`: **EXPERIMENTAL** Allows to change Rack's behavior\n  on obtaining the Rack environment. The default behavior is that parameter\n  parsing is left to be done by the Rack::Request itself (by consuming the\n  request body in case of a POST), but if the servlet request's input stream has\n  been previously read this leads to a limitation (Rack won't see the POST paras).\n  Thus an alternate pure 'servlet' env \"conversion\" is provided that maps servlet\n  parameters (and cookies) directly to Rack params, avoiding Rack's input parsing.\n- `jruby.rack.filter.adds.html`:\n  **deprecated** use `addsHtmlToPathInfo` filter config init parameter.\n  The default behavior for Rails and many other Ruby applications is to add an\n  *.html* extension to the resource and attempt to handle it before serving a\n  dynamic request on the original URI.\n  However, this behavior may confuse other servlets in your application that\n  have a wildcard mapping. Defaults to true.\n- `jruby.rack.filter.verify.resource.exists`:\n  **deprecated** use `verifiesHtmlResource` filter config init parameter.\n  If `jruby.rack.filter.adds.html` is true, then this setting, when true, adds\n  an additional check using `ServletContext#getResource` to verify that the\n  *.html* resource exists. Default is false.\n  (Note that apparently some servers may not implement `getResource` in the way\n  that is expected here, so in that case this setting won't matter.)\n\n## Initialization\n\nThere are often cases where you need to perform custom initialization of the\nRuby environment before booting the application. You can create a file called\n*META-INF/init.rb* or *WEB-INF/init.rb* inside the war file for this purpose.\nThese files, if found, will be evaluated before booting the Rack environment,\nallowing you to set environment variables, load scripts, etc.\n\nFor plain Rack applications, JRuby-Rack also supports a magic comment to solve\nthe \"rackup\" chicken-egg problem (you need Rack's builder loaded before loading\nthe *config.ru*, yet you may want to setup the gem version from within the rackup\n file). As we ship with the Rack gem bundled, otherwise when executing the\nprovided *config.ru* the bundled (latest) version of Rack will get loaded.\n\nUse **rack.version** to specify the Rack gem version to be loaded before rackup :\n\n    # encoding: UTF-8\n    # rack.version: ~\u003e2.2.10 (before code is loaded gem '~\u003e2.2.10' will be called)\n\nOr the equivalent of doing `bundle exec rackup ...` if you're using Bundler :\n\n    # rack.version: bundler (requires 'bundler/setup' before loading the script)\n\n\n## Logging\n\nJRuby-Rack sets up a delegate logger for Rails that sends logging output to\n`javax.servlet.ServletContext#log` by default. If you wish to use a different\nlogging system, configure `jruby.rack.logging` as follows:\n\n- `servlet_context` (default): Sends log messages to the servlet context.\n- `stdout`: Sends log messages to the standard output stream `System.out`.\n- `slf4j`: Sends log messages to SLF4J. SLF4J configuration is left up to you,\n  please refer to http://www.slf4j.org/docs.html .\n- `log4j`: Sends log messages to log4J. Again, Log4J configuration is\n  left up to you, consult http://logging.apache.org/log4j/ .\n- `commons_logging`: Routes logs to commons-logging. You still need to configure\n  an underlying logging implementation with JCL. We recommend using the logger\n  library wrapper directly if possible, see http://commons.apache.org/logging/ .\n- `jul`: Directs log messages via Java's core logging facilities (util.logging).\n\nFor those loggers that require a specific named logger, set it with the\n`jruby.rack.logging.name` option, by default \"jruby.rack\" name will be used.\n\n\n## Building\n\nCheckout the JRuby-Rack code using [git](http://git-scm.com/) :\n\n    git clone git://github.com/jruby/jruby-rack.git\n    cd jruby-rack\n\nEnsure you have [Maven](http://maven.apache.org/) installed.\nIt is required for downloading jar artifacts that JRuby-Rack depends on.\n\nBuild the .jar using Maven :\n\n    mvn install\n\nthe generated jar should be located at **target/jruby-rack-*.jar**\n\nAlternatively use Rake, e.g. to build the gem (skipping specs) :\n\n    jruby -S rake clean gem SKIP_SPECS=true\n\nYou can **not** use JRuby-Rack with Bundler directly from the git (or http) URL\n(`gem 'jruby-rack', :github =\u003e 'jruby/jruby-rack'`) since the included .jar file\nis compiled and generated on-demand during the build (it would require us to\npackage and push the .jar every time a commit changes a source file).\n\n## Releasing\n\n* Make sure auth is configured for \"ossrh\" repository ID in your .m2/settings.xml\n* Update the version in src/main/ruby/jruby/rack/version.rb to the release version\n* mvn release:prepare\n* mvn release:perform (possibly with -DuseReleaseProfile=false due to Javadoc doclint failures for now)\n* rake clean gem SKIP_SPECS=true and push the gem\n\n## Support\n\nPlease use [github][4] to file bugs, patches and/or pull requests.\nMore information at the [wiki][5] or ask us at **#jruby**'s IRC channel.\n\n[1]: https://github.com/jruby/warbler#warbler--\n[2]: https://oss.sonatype.org/content/repositories/releases/org/jruby/rack/jruby-rack/\n[3]: https://github.com/trinidad/trinidad\n[4]: https://github.com/jruby/jruby-rack/issues\n[5]: https://wiki.github.com/jruby/jruby-rack\n[8]: http://badge.fury.io/rb/jruby-rack\n[9]: https://github.com/jruby/jruby-rack/actions/workflows/maven.yml\n","funding_links":[],"categories":["网络编程"],"sub_categories":["Spring Cloud框架"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-rack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjruby%2Fjruby-rack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-rack/lists"}