2. About Me
Advisory Engineer at Constant Contact
Spent several years working for Sun/Javasoft in
the distributed computing group
Email: jerry@gulla.com
Twitter: @jerrygulla
Github: github.com/jgulla
3. What is JRuby?
Just a Ruby interpreter running on the JVM
Ruby 1.8.7 & 1.9.2 compatible.
8. Why Ruby?
Ruby is…A dynamic, open source programming
language with a focus on simplicity and
productivity. It has an elegant syntax that is natural
to read and easy to write.
10. WHY SHOULD YOU SWITCH TO RUBY? IF YOU ARE HAPPY WITH
PERL OR PYTHON, YOU DON'T HAVE TO. BUT IF YOU DO FEEL
THERE MUST BE A BETTER LANGUAGE, RUBY MAY BE YOUR
LANGUAGE OF CHOICE. LEARNING A NEW LANGUAGE IS
HARMLESS. IT GIVES YOU NEW IDEAS AND INSIGHTS. YOU
DON'T HAVE TO SWITCH, JUST LEARN AND TRY IT. YOU MAY
FIND YOURSELF COMFORTABLE ENOUGH WITH RUBY TO
DECIDE TO SWITCH TO IT.
-- YUKIHIRO MATSUMOTO (“MATZ”)
HTTP://LINUXDEVCENTER.COM/PUB/A/LINUX/2001/11/29/
RUBY.HTML
12. Why Not Grails?
Grails is great
Not as big of a break with Java
Wanted a bigger shift to bring new ways of doing
things into perspective.
13. Why JRuby?
High performance
JVM Highly Tuned
Real threading
Many “pure Ruby” shops using JRuby just for
this
Vast array of libraries
No need to abandon Java libraries.
14. Why JRuby Continued
Deployment Options
Can deploy as a WAR file
Monitoring Options
JVM tools to monitor all available
Speed of Development.
15. Don’t Freak the Ops
Guys Out
HTTP://UPLOAD.WIKIMEDIA.ORG/WIKIPEDIA/EN/F/F4/THE_SCREAM.JPG
17. Concurrency is a Myth
HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
18. ILYA GRIGORIK
HTTP://WWW.IGVITA.COM/ABOUT/
JRUBY IS, IN FACT, THE ONLY RUBY IMPLEMENTATION
THAT WILL ALLOW YOU TO NATIVELY SCALE YOUR RUBY
CODE ACROSS MULTIPLE CORES. BY COMPILING RUBY
TO BYTECODE AND EXECUTING IT ON THE JVM, RUBY
THREADS ARE MAPPED TO OS THREADS WITHOUT A GIL
IN BETWEEN - THAT'S AT LEAST ONE REASON TO LOOK
INTO JRUBY.
HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
24. Installing RVM
Via git repo (preferred method)
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Other methods at https://rvm.beginrescueend.com/rvm/install/
25. Install JRuby (via rvm)
rvm install jruby-1.6.3
When it’s done, use it:
rvm use jruby-1.6.3
List of other ruby versions to install:
rvm list known
List versions of ruby you have installed:
rvm list
28. Create Your Rails App
Jruby.org hosts a rails template
Sets things up to run under native ruby or JRuby
You can do this yourself, but it’s handier to start this
way
rails new uberconf_demo --template=http://jruby.org
Works with native ruby or JRuby.
32. Packaging Your App
http://en.wikipedia.org/wiki/File:Distribution_differences.jpg
33. JRuby/Rails/WAR files
In the Java world, WAR files are standard
Fortunately, we have bundler
Gem to package your Rails app as a WAR file
Can even make it “Executable” for stand-alone
testing!
http://caldersphere.rubyforge.org/warbler/
35. Run It
http://en.wikipedia.org/wiki/File:Jeanette_Kwakye_cropped.jpg
Easy!
warble war
36. Other Useful Options
warble compiled # Feature: precompile all Ruby files
warble config # Generate a configuration file to customize your archive
warble executable # Feature: make an executable archive
warble gemjar # Feature: package gem repository inside a war
warble pluginize # Install Warbler tasks in your Rails application
warble version # Display version of Warbler
warble war # Create the project war file
warble war:clean # Remove the project war file
warble war:debug # Dump diagnostic information
37. Maven
In the Java world, Maven is still pretty popular
For better or for worse
You can use Maven to invoke warbler to package
your app.
40. Database Migrations
Rails uses Rake for ActiveRecord migrations
Nice, but
Hard to scale to multiple developers
Hard to deploy to QA/Production systems
without using ruby toolset
Paranoid DBAs can’t see the SQL before
running it.
42. Liquibase
Nothing special about using Liquibase with Rails
Use ActiveRecord migrations for initial dev/testing,
then migrate to Liquibase
When ready, just take “snapshot” of DB config,
then roll out new Liquibase changesets.
43. Handy Liquibase Commands
Generate initial changelog:
java -jar liquibase.jar --classpath=mysql-connector-
java-5.1.14-bin.jar --url=jdbc:mysql://localhost/
api_development --driver=com.mysql.jdbc.Driver --
username=demo --password=password --
changeLogFile=db-changelog.xml generateChangeLog
Drop all tables so you can start over:
dropAll
Run updates against a DB:
liquibase --changeLogFile=myChangeLog update
Just output SQL, don’t run: updateSQL
48. Servlet Filters
You’ll need a custom web.xml config
Copy WARBLER_HOME/web.xml.erb to
config/web.xml.erb
Look for it at ~/.rvm/gems/jruby-1.6.2/gems/
warbler-1.3.1/web.xml.erb
HTTP://EN.WIKIPEDIA.ORG/WIKI/FILE:DICHROIC_FILTERS.JPG
58. Set Root Path for App
By default, the root of your app is the WAR name
This may not be what you want.
59. Set the Root Path
Create file jboss-web.xml in root of app directory
Tell warbler to include it via warble.rb
60. Bundle Up Files into A
Gem
Can be much faster to build/deploy depending on
how you do it (there are a lot of files!)
Make sure to test it
61. Make Your War Executable
Command Line:
warble executable war
In warble.rb:
config.features = %w(executable)
62. Rails Console
Rails has a “Console Mode” for testing
Great for trying out ActiveRecord queries, etc.
Just use “rails console” to invoke it.
63. Gem Versions
Be sure to lock down Gem versions when you’re
happy with them
Don’t want any last minute “upgrades!”
Use bundler
Put Gemfile.lock under source control.
64. Basic Versioning Rules
After bundling, always check your Gemfile.lock
into version control
After updating your Gemfile, always run
bundle install first.
When running an executable, ALWAYS use
bundle exec [command]
The only exception is the rails command!
http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/