DISQUS

ADS Blog: Deploy Your First JRuby on Rails App to Glassfish

  • AkitaOnRails · 2 years ago
    That's another really nice tutorial. I hope more people jot down specifics for more deployment procedures under other app servers as JBoss, Websphere and what have you. On the other hand, before Rails I've developing heavily under 1.4.2 only, so I missed 1.5 and 1.6 altogether. I was assuming that since 1.6 is now OpenJava, someone would have it ported to work reliably on Mac OS X. Anyone knows something about it?
  • anonymous · 2 years ago
    any idea if rails integration plugin can be used to develop servlets or something similar to a mongrel handler?
  • Robert Dempsey · 2 years ago
    Not that I know of. I would check out the JRuby site for that one. If you find out let us know.
  • nap · 2 years ago
    excellent tutorial guys, many thanks.
  • nap · 2 years ago
    couple comments tho..

    1) current version of the mysql connector is 5.0.6, not 5.0.4 (but obviously it's just whatever you have)
    2) goldspike makes some assumptions about the name of the jar files you tell it to add. the default name of the mysql connector when you download the binary version ends in -bin (after the version). you should rename it to mysql-connector-java-5.0.6.jar and make sure it's in your JRUBY_HOME/lib directory (make sure to add that to your .bash_profile or equivalent startup script)
  • Robert Dempsey · 2 years ago
    Nap,

    Thanks for catching that. Ironically, I have the 5.0.6 in my jruby/lib directory. I have updated the tutorial. Thanks for the goldspike info as well.
  • AkitaOnRails · 2 years ago
    Hello again. I spent the whole day trying this tutorial with jruby 1.0 and several things went very wrong. I still don't know the whole reasons, perhaps the fact that I installed my jruby at /opt/local/jruby. After a lot of experimentation, I had to patch Goldmine to support jruby 1.0 (the trunk still used 0.9.9), I had to add all the other .jar dependencies from the jruby/bin (as backport). Then I had to patch it to generate a WEB-INF/web.xml with explicit jruby.home and gem.home set.

    My database.yml was using variables as well (production was pointing to development for DRY sake) but the Java YAML parser complained and I had to copy the entire development setting to production as well. Only then my app ran in Glassfish.

    Even then it didn't ran 100%: my testbed app was a slightly customized Redmine and file uploading still didn't work. I still didn't figured out what was the reason for that.

    On the other hand I also had to patch ActiveRecord-JDBC because it recognizes :boolean as tinyint(1) and bit(1) but it complained about 'bit', so I added that to the adapter as well (through opening its class in environment.rb). Only then the unit and funcional tests passed. But the integration testes failed miserably return HTTP 500. Probably something in the CGI support that I still didn't figure out.

    Anyone had the same trouble? I want to share some experiences on that. If anyone can read portuguese, take a look at my detailed report at (http://www.akitaonrails.com/articles/2007/06/10...). All the patches I applied to my working copy are there as well.
  • Robert Dempsey · 2 years ago
    Akita,

    I am sorry to hear that you ran into so many issues. I thank you for posting them here, and hope that your experience will help others in your shoes. You do bring up a good point as well - the proper application of JRuby.

    I have been talking a lot with friends (other developers both Java and Ruby/Rails) about when to use JRuby. I will keep the opinions for another post, however, the consensus was "if it ain't broke don't fix it." In other words, if your Rails app works well running on Mongrel+Apache or whatever your setup is, leave it there. Do you need to plug into Java libraries? If the answer is yes, then go for it, but keep testing as you go.

    Thank you again for the post of your experience.

    By the way, I had to download the latest Goldspike plugin once I started using JRuby 1.0. In addition, I had to include the path to jruby/lib in my $PATH.
  • nap · 2 years ago
    You should also note that goldspike's war_config.rb should be updated to specify the jruby-complete-1.0 jar instead of the 0.99 one. Until it's available at the appropriate remote sources, you'll probably want to download the jar from codehaus and place it in your $JRUBY_HOME/lib directory so goldspike can find it.
  • nap · 2 years ago
    Btw, I took a few additional notes (mostly about providing openssl support) and recorded them on my blog here. Thanks again for the great tut.
  • Robert Dempsey · 2 years ago
    Thanks for the additional info nap! I will definitely check out your additional notes.
  • anonymous · 2 years ago
    Has anyone done any benchmarking to compare performance of rails deployed to an appserver vs. a mongrel_jcluster?
  • Robert Dempsey · 2 years ago
    I haven't seen any yet. I am definitely looking for it though. If you find any please post it. Thanks.
  • dsuspense · 2 years ago
    For those interested in installing JRuby on Windows and getting a simple JRuby app up and running, please check out the following link:

    http://www.developer.com/lang/article.php/3669041
  • Robert Dempsey · 2 years ago
    Thanks for the links to the other tutorials Dominic. They look great.
  • Duane · 2 years ago
    Does anybody know if I can use JRuby to go in the other direction, namely calling Ruby from existing Java code? We run Java app servers here and I thought it would be neat to be able to code up some of my business logic / rule engine sorts of things in Ruby and just link them in, rather than having to go through the trouble of making a web service out of them.
  • Robert Dempsey · 2 years ago
    @Duane,

    Check out the JRuby mailing lists. I have seen people discussing it on the "user" list.

    http://xircles.codehaus.org/projects/jruby/lists
  • khelll · 2 years ago
    i got this when i try to widgets controller:
    javax.servlet.ServletException: Could not load Rails. See the logs for more details.
    org.jruby.webapp.RailsFactory.makeObject(RailsFactory.java:131)
    org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
    org.jruby.webapp.AbstractRailsServlet.serviceRequest(AbstractRailsServlet.java:144)
    org.jruby.webapp.AbstractRailsServlet.service(AbstractRailsServlet.java:131)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.jruby.webapp.FileServlet.doGet(FileServlet.java:102)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  • Robert Dempsey · 2 years ago
    @khelll - what does your environment.rb file look like? You want to make sure that you have the following in there:

    if RUBY_PLATFORM =~ /java/
    require 'rubygems'
    RAILS_CONNECTION_ADAPTERS = %w(jdbc)
    end

    Put that under the "require File.join" line. If that doesn't work let me know. Thanks.
  • florin · 2 years ago
    That’s a really nice tutorial! It helped me while I did my own JRuby integration with JPublish ( http://weblog.flop.ca/2007/07/17/1184705235053....) and I can confirm that being able to run Ruby in Java (JPublish Actions in my case) is very exciting. Thank you for the nice articles.
  • Robert Dempsey · 2 years ago
    Florin,

    Thank you for the great feedback. We are working on turning this tutorial into a screencast and should have it released soon.
  • Arun Gupta · 2 years ago
    I published a series of tutorials couple of months ago at:
    http://blogs.sun.com/arungupta/entry/ruby_on_ra..., http://blogs.sun.com/arungupta/entry/database_e... and http://blogs.sun.com/arungupta/entry/database_e...

    I'm working on a screencast version of these tutorials using NetBeans 6 M10.

    Thanks,
    -Arun
  • Robert Dempsey · 2 years ago
    Arun,

    Thanks for posting your tutorials. They have definitely helped me out. I look forward to the screencasts for NetBeans as well.
  • Arun Gupta · 2 years ago
    Robert, Glad you liked the entries. The screencast is now available at: http://blogs.sun.com/arungupta/entry/screencast...

    Enjoy!
  • Robert Dempsey · 2 years ago
    Thanks Arun. I look forward to watching it. Keep us up on all the latest.
  • Gianluca Tessarolo · 2 years ago
    I try to work with GlassFish V3 gem / Jruby 1.0.2 and Rails 1.2.5: all works well but I don't understand why GlassFish doesn't handle concurrent requests.

    If one controller action is a bit slow (eg. 10 seconds long) the other actions don't render anything (no response from GlassFish, only a blank page).

    To test it simply put "sleep 10" before render into an action controller code...

    Does someone have tested this simple case ?

    Thanks in advance !
  • Imran Lakhani · 1 year ago
    Thanks Pal,

    This tutorial was really very worth and deserve to be bookmarked :)
    It was very very helpful
  • gez · 2 months ago
    Hi,

    like the article. A note about the java version that runs by default on Mac OS X, you can switch versions using the '/Applications/Utilities/Java Preferences' application - just drag the version you want as your default to the top of the list (there's a list for applets and another for applications). I'd advise against changing things in /System/Library/Frameworks unless you really know what your doing (I have and subsequently screwed up my java installation - stopped me from using java, thankfully TimeMachine came to the rescue).