Rails專案中jRuby與Scala的互動

jieforest發表於2012-06-24

The JVM is awesome.


But back to the topic of this post: We’ll see how you can leverage both Scala andJRuby in one project. Each will doing what it does best:


1. Ruby will handle the FAST frontend development as one of Ruby’s strong points is obviously Rails which made it so popular. Though there are people implementing APIs in ruby, if you need pure performance, you may need some other lang (vide airbreak, twitter…).


2. Scala will be doing all the heavy lifting including some of our existing code which interacts with zookeeper or uses Akka actors to crunch some numbers.


Another great point here is the reuse of our existing scala codebase which has some nice libraries we’ve implemented during our day-to-day. Anyway, let’s see some code!


Start out with a plain Rails 3.2 project


You know the drill. rvm, ruby, rails new. The only difference here is that we’ll use JRuby right from the start here, so:

CODE:

# get JRuby and start a new rails app
rvm install jruby && rvm use jruby

gem install rails
rails new scala-on-railsJRubify it!

Next we’ll add some more dependencies to our Gemfile:

CODE:

# jruby dependencies in Gemfile
gem 'jruby-openssl' # simply required
gem 'jruby-scala' # a jruby scala bridge
gem 'warbler' # to create a war file that we'll deploy layer

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-733665/,如需轉載,請註明出處,否則將追究法律責任。

相關文章