Embed JRuby Rack applications in your Java container.
In a Maven project, add rack-servlet
and jruby-complete
to your pom.xml
:
<dependencies>
<dependency>
<groupId>com.squareup.rack</groupId>
<artifactId>rack-servlet</artifactId>
<version>${rack.servlet.version}</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>${jruby.version}</version>
</dependency>
</dependencies>
// Use JRuby to build your Rack application:
ScriptingContainer ruby = new ScriptingContainer();
IRubyObject application = ruby.parse("lambda { |env| [200, {}, ['Hello, World!']] }").run();
// Build a RackServlet with that Rack application:
Servlet servlet = new RackServlet(new JRubyRackApplication(application));
// Install that servlet in your container...
// (See our examples directory for concrete code.)
pom.xml
on
your test classpath. For production deployments, you'll need to be a little
more clever.rack.logger
and rack.errors
use slf4j, so that you can choose
your logging backend. Log messages are written to
com.squareup.rack.RackLogger
and com.squareup.rack.RackErrors
,
respectively.Rack Servlet grew out of our desire to embed Rack applications in Square's Java service container, in order to take advantage of our sophisticated infrastructure.
There are other options in the "run Rack applications on the JVM" space, all of which are shaped somewhat differently: