[jruby-user] Running a JRuby on Rails app alongside Java servlets

0 views
Skip to first unread message

Demetrius Nunes

unread,
Aug 5, 2009, 2:23:37 PM8/5/09
to us...@jruby.codehaus.org
Is it possible to run a JRuby on Rails application alongside regular Java servlets?

My scenario is the following:

I have a legacy Java web application (that uses the Tapestry web framework) and we would like to write some new functionality for it, but instead of using Java, we would like to do it in JRuby with Rails. But we can't run 2 separate apps, the old Java and the new JRuby code has to remain within the same application and run alongside each other.

Is it possible? How could it be done?

Cheers,
Demetrius
--
____________________________
http://www.demetriusnunes.com

Jesús García Sáez

unread,
Aug 5, 2009, 2:46:40 PM8/5/09
to us...@jruby.codehaus.org

I guess that it depends on how your servlets are mapping right now. A
web.xml for rails looks like:

<web-app>
...
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>


so i guess if you put your servlet declaration before the RackFilter
one, everything should work fine. But if the servlets you are using
need to use that pattern, /*, none of the request will reach the rails
application.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Demetrius Nunes

unread,
Aug 5, 2009, 3:40:26 PM8/5/09
to us...@jruby.codehaus.org
Thanks, that seems like a viable and not so difficult way.

I'll try my hand at it and see how it works out.

Cheers,
Demetrius

2009/8/5 Jesús García Sáez <bla...@gmail.com>



--
____________________________
http://www.demetriusnunes.com

Charles Oliver Nutter

unread,
Aug 5, 2009, 8:26:22 PM8/5/09
to us...@jruby.codehaus.org
2009/8/5 Jesús García Sáez <bla...@gmail.com>:

> I guess that it depends on how your servlets are mapping right now. A
> web.xml for rails looks like:
>
> <web-app>
> ...
>  <filter-mapping>
>    <filter-name>RackFilter</filter-name>
>    <url-pattern>/*</url-pattern>
>  </filter-mapping>
> ...
> </web-app>

I wonder if it would be worth expanding Warbler to work better with
existing Java servlets/applications, and maybe even make Warbler work
as a general-purpose packager?

I have to admit, I've never really wrapped my head around exactly how
JRuby, Rack, RackFilter, Warbler, and Rails fit together. I think the
ability to stuff a Rails app into an existing WAR file would be truly
outstanding, and something we should make as easy as possible.

And of course with Rails 3, there's the possibility of plugging normal
Java-land libraries into Rails like Hibernate or JSPs, so we need to
start working to blur the lines.

- Charlie

James Abley

unread,
Aug 6, 2009, 3:27:36 AM8/6/09
to us...@jruby.codehaus.org


2009/8/6 Charles Oliver Nutter <hea...@headius.com>

2009/8/5 Jesús García Sáez <bla...@gmail.com>:
> I guess that it depends on how your servlets are mapping right now. A
> web.xml for rails looks like:
>
> <web-app>
> ...
>  <filter-mapping>
>    <filter-name>RackFilter</filter-name>
>    <url-pattern>/*</url-pattern>
>  </filter-mapping>
> ...
> </web-app>

I wonder if it would be worth expanding Warbler to work better with
existing Java servlets/applications, and maybe even make Warbler work
as a general-purpose packager?

I have to admit, I've never really wrapped my head around exactly how
JRuby, Rack, RackFilter, Warbler, and Rails fit together. I think the
ability to stuff a Rails app into an existing WAR file would be truly
outstanding, and something we should make as easy as possible.

And of course with Rails 3, there's the possibility of plugging normal
Java-land libraries into Rails like Hibernate or JSPs, so we need to
start working to blur the lines.

- Charlie

I had a brief stab a while ago at getting RackFilter working on /r/* and having another servlet processing /m/*. Didn't quite get there; you need to delve a bit into Rails and Rack to set prefix paths. I'd be interested in hearing how you get on.

Cheers,

James

Justin Coyne

unread,
Aug 6, 2009, 11:20:57 AM8/6/09
to us...@jruby.codehaus.org
You just need to put your own web.xml file in the rails/config
directory. This will be used instead of the one generated by warbler.
I have production apps running rails and struts in the same servlet
container.


<!--RAILS CONFIG-->
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/r/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>

<!--STRUTS CONFIG-->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
...
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/m/*.do</url-pattern>
</servlet-mapping>

Hassan Schroeder

unread,
Aug 6, 2009, 11:38:28 AM8/6/09
to us...@jruby.codehaus.org
On Thu, Aug 6, 2009 at 12:27 AM, James Abley<james...@gmail.com> wrote:

> I had a brief stab a while ago at getting RackFilter working on /r/* and
> having another servlet processing /m/*.

Since Filters are evaluated in web.xml-defined-order, couldn't you
have an initial control Filter (both Filters mapped to /*) where the first
forwards to your other servlet(s) based on whatever desired mapping
(breaking the Filter chain) and everything else defaults to Rails?

Untested, but similar to what I've done in other Java apps.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan

Reply all
Reply to author
Forward
0 new messages