jRuby Workshop
The last decade has seen an explosion in the number of languages targeting the Java runtime. Amongst these, one of the (arguably) strong contenders is JRuby - a 100% Java port of the Ruby language. Ruby aims to make programmers "happy", and with JRuby you can find happiness without having to leave your favorite runtime! JRuby also provides deep integration with Java, allowing you to leverage existing Java libraries while writing code that is succinct, elegant and beautiful.
In this hands-on workshop we will talk about JRuby the language, explore it's syntax and constructs like classes and modules. We will discuss advanced topics like meta-programming and domain specific languages, see how we can write Java applications without writing Java code, and some potential gotchas.
Feel a sense of elation? Already rubbing your hands in glee? Well look no further than this workshop - with lot's of examples and practice code (read: bring a laptop) to work with, you will certainly walk away feeling a sense of euphoria.
Workshop Requirements
This session is a workshop. Please come prepared.
JRuby Workshop Setup
Java
- Have Java 1.6+ installed
To check this simply fire up a command line prompt and run
java -version. This is what shows up on my computer$ java -version java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3635) Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)If you don't have Java installed (or pre 1.6) you can download it here
- Make sure to run
java -versionon the command line after installation to make sure that youPATHis set up correctly
JRuby
- You can download JRuby here
- NOTE - JRuby 1.7 can leverage some of the newer JVM instructions such as
invokeDynamicso it works best with Java 1.7. For this workshop JRuby 1.6.7.2 will also work. After installation, fire up a command prompt and run
jruby -vto make sure that yourPATHis set up correctly. This is what shows up on my computer$ jruby -v
Listening for transport dt_socket at address: 5005
jruby 1.6.5.1 (ruby-1.9.2-p136) (2011-12-27 1bf37c2) (Java HotSpot(TM) 64-Bit Server VM 1.6.031) [darwin-x8664-java]Note that it says
ruby-1.9.2as the Ruby version it is using.- If it does not say
ruby-1.9.2tryexport JRUBY_OPTS="--1.9"on your command line and then tryjruby -vagain. This will force JRuby to be Ruby 1.9 compatible.
RVM or rbenv Users (Mac OSX only)
- You can follow the instructions here to install JRuby alongside any other Rubies you might have installed.
- Once again, if running
jruby -vdoes not show it as using Ruby 1.9 then tryexport JRUBY_OPTS="--1.9"and runjruby -vagain.
Editor
- Have any editor installed that you like, and that preferably understands Ruby syntax. Here are a few options (I am personally inclined to - SublimeText and emacs - Both work across all operating systems)
- Sublime Text [Highly recommended]
- Emacs (For all OSes), AquaEmacs (Mac OSX only) - Here is another download site for emacs on Mac OSX
- Notepad++ (for Windows)
Directory setup
- Create a directory called
jRubyWorkshop(or something like that) somewhere on your computer. Avoid white space in your directory path if you can.C:\jRubyWorkshopis preferable to sayC:\Documents and Settings\jRubyWorkshop. For Mac and Linux users anything under yourhomedirectory will work. cdto the newly created directory, and create a new file calledtest_jruby_install.rb. Open it in your favorite text editor and type in the following lineputs "You have JRuby working with #{RUBY_VERSION}. Woohoo!!"
Save the file, go back to the command line, make sure you are in the right directory, and run
jruby test_jruby_install.rb. You should see
You have JRuby working with 1.9.2. Woohoo!!
- You can delete this file if you wish.
- Now, within the
jRubyWorkshopdirectory, create alibdirectory, and asrcdirectory. This is what your
treeshould look like.
- jRubyWorkshop/
- lib/
- src/
- lib/
- jRubyWorkshop/
iText
- Awesome. We are almost done. Download iText jar from here, unzip it and put the
itextpdf-5.2.1.jarfile in your newly createdlibdirectory under thejRubyWorkshopdirectory.
Feeling ambitious?
- If you feel like playing around with Ruby prior to coming to the workshop, head over to tryruby.org - It only takes 15 mins :)
Done! Now you are all set for our workshop. Hope to see you guys soon!
About Raju Gandhi
Raju Gandhi is a Java/Ruby developer and a programming language geek. He has been writing software for the better part of a decade in several industries including education, finance, construction and the manufacturing sector. Raju has a graduate degree in Industrial Engineering from Ohio University. In his spare time you will find Raju reading, or watching movies, or playing with yet another programming language. He is affectionately known as looselytyped on Twitter.
More About Raju »






