views:

884

answers:

6

Essentially the only thing I can deploy to my deployment machine is a JAR file. I can't install JRuby, nor can I install Glassfish or Tomcat.

Is it possible to package up a Rails application (including Rails, vendored, of course) to a JAR file such that I can do

c:\my_server> java rails_app.jar

and have it run WEBRick or Mongrel within the JVM?

+3  A: 

I'd recommend that you checkout Jetty. The process for Embedding Jetty is surprisingly easy, and it should be possible to give it your servlets from your current jar file. I haven't used Ruby/Rails, though, so I'm not sure if there are any complications there.

Is it normally possible to embed all of your rails templates/models into a jar inside of a war file for deployment on Tomcat? If so, then you should be able to get embedded Jetty to pull it from your single jar as well.

jsight
+1  A: 

I don't think you can run Mongrel within the JVM. Trying to run a webserver of any kind without Tomcat or Jetty is probably way more trouble than it's worth. jsight's answer looks helpful for that problem. If you can get that far, here's a page on JRuby's site about running JRuby on Rails in Tomcat.

sblundy
+6  A: 

I wrote an article a year ago about how to embed your ruby sources with jruby and everything else you want into one jar file, and then run it with "java -jar myapp.jar".

It will need some work to make it boot rails I guess, but it should not be too hard. And with the complimentary jruby documentation on their wiki, i guess you can run a jetty+war thing fairly easily with this technique.

The article is here: http://blog.kesor.net/2007/08/14/jruby-in-a-jar/

Evgeny
+1  A: 

you might want to try asking this question on the JRuby mailing list/forum(http://xircles.codehaus.org/lists/[email protected]).

Another place someone would have done the same is the glassfish mailing list

Yet another thing you might want to do is to bundle winstone embeddable servlet container AND jruby AND rails and use jarjar to create one big jar. You might be able to build an ant build file to build such a BIG jar that also includes your rails application. One project that used this approach is hudson(https://hudson.dev.java.net/) -- you may get some info on how to go about doing that.

BR,
~A

anjanb
i would suggest using one-jar instead of jarjar, since jarjar explodes jars and zips the classes. one-jar leaves the jars intact.
Evgeny
+2  A: 

It may be a bit dated, but Nick Sieger, one of the JRuby contributors wrote about warbler a while ago.

Warbler is about packaging a Rails app into a .war file. Now I'm not a big Java guy, si I'm not sure where your .jar restriction comes from. war files are similar to jars but they're for whole websites or something.

Worst case, I'm pretty sure the JRuby wiki has something about the state of packaging Rails apps to be run on Java architectures. It's in their best interest to have info about that.

webmat
A: 

I just ran across this blog today, and I intend on giving it a try, if anyone else has let me know

http://matthewkwilliams.com/index.php/2010/03/02/rails-jruby-in-a-jar/

Cognition.Mind