You are viewing details from a past event. Please check our upcoming event schedule if you are looking for current content.

jRuby Workshop

Thursday, 3:15 PM MDT - Lake House

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™ SE Runtime Environment (build 1.6.0_31-b04-415-11M3635)
    Java HotSpot™ 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 -version on the command line after installation to make sure that you PATH is set up correctly

JRuby

  • You can download JRuby here

  • NOTE - JRuby 1.7 can leverage some of the newer JVM instructions such as invokeDynamic so 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 -v to make sure that your PATH is 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™ 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]

  • Note that it says ruby-1.9.2 as the Ruby version it is using.

  • If it does not say ruby-1.9.2 try export JRUBY_OPTS="--1.9" on your command line and then try jruby -v again. 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 -v does not show it as using Ruby 1.9 then try export JRUBY_OPTS="--1.9" and run jruby -v again.

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)

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:\jRubyWorkshop is preferable to say C:\Documents and Settings\jRubyWorkshop. For Mac and Linux users anything under your home directory will work.

  • cd to the newly created directory, and create a new file called test_jruby_install.rb. Open it in your favorite text editor and type in the following line

    puts “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 jRubyWorkshop directory, create a lib directory, and a src directory.

  • This is what your tree should look like

    .

    • jRubyWorkshop/
      • lib/
      • src/

iText

  • Awesome. We are almost done. Download iText jar from here, unzip it and put the itextpdf-5.2.1.jar file in your newly created lib directory under the jRubyWorkshop directory.

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

Raju is a software craftsman with almost 20 years of hands-on experience scoping, architecting, designing, implementing full stack applications.

He provides a 360 view of the development cycle, is proficient in a variety of programming languages and paradigms, experienced with software development methodologies, as well an expert in infrastructure and tooling.

He has long been in the pursuit of hermeticism across the development stack by championing immutability during development (with languages like Clojure), deployment (leveraging tools like Docker and Kubernetes), and provisioning and configuration via code (toolkits like Ansible, Terraform, Packer, everything-as-code).

Raju is a published author, internationally known public speaker and trainer.
Raju can be found on Twitter as @looselytyped.
In his spare time, you will find Raju reading, playing with technology, or spending time with his wonderful (and significantly better) other half.

More About Raju »