GlassFish and
JRuby are obviously a great match, since both run
on the Java virtual machine which allows Ruby code running on JRuby to
access Java framework and libraries and the possibilities are endless.
However, GlassFish is also capable of running Ruby code via a native
Ruby interpreter. This is possible using CGI support in GlassFish.
For this first post, I shall keep things simple and demonstrate how you
could go about dedicating an entire instance of the GlassFish server for
a single RoR application
All you'll need is to install
GlassFish v2 build 29 or greater, the native Ruby interpreter with the Rails framework libraries
and make some minor modifications to GlassFish configuration. Of course, you'll need to create your rails application. The minor modifications amount to modifying
${glassfish.home}/domains/${domain-name}/config/default-web.xml with the following
CGI configuration enabled.
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<!-- in this case the path will be appended to
${glassfish.home}/domains/${domain-name}/docroot/ -->
<param-name>cgiPathPrefix</param-name>
<param-value>${rails-root-dir}/public/dispatch.cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>${path-to-ruby}</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
...
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
On UNIX make sure that the native Ruby interpreter is in the PATH and
LD_LIBRARY_PATH is set to satisfy the native Ruby interpreter's/Rails
dependencies in the GlassFish process's environment. This
is the reason for configuring the 'passShellEnvironment' parameter
to true.
That's pretty much all there is to it. Accessing http://${host}:${port}/
should bring up the default Rails page !