Using Java in Rails

{{{
Little Nick just found out that it is so easy to *use Java in a Ruby and Rails* environment.

We were using Jruby 1.5 or something and Rails 3, having a file @Phonetic.jar@ which provided a static @encode@ method that we needed in a model.

I simply moved the file to @lib/java/phonetic.jar@ and extended the model like this.

extend Java
require "java/phonetic.jar"

class Whatever < ActiveRecord::Base
  # ..
  def encrypt(string)
    Java.Phonetic.encode(string)
  end

It’s so awesome that you *simply can work with Java classes in your Ruby code*.

Yeah, I know, all of you guys did that like 5 years ago, but *I am still amazed and wanted to share that experience*.

Hooray for the Jruby!
}}}

Advertisements

One thought on “Using Java in Rails

  1. This looks great!. I’m still learning Rails and Ruby. Are there plans for some kind of pallete where I can see all the widgets ?. Also looking for a design tool to allow me to design a dashboard by drag and drop widgets.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s