Wednesday Feb 18, 2009

Using Gems With JRuby

If you are new to JRuby, you might not know that you cannot use a gem that has native extensions with JRuby, unless that gem builds its library in a platform-neutral manner. When you use the JRuby gem executable to try to add such a gem to your repository, you will get a message like this.

Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

C:/jruby/jruby-1.1.5/bin/jruby.bat extconf.rb install rmagick --no-rdoc --no-ri
C:/jruby/jruby-1.1.5/lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (NotImplementedError)
    from C:/jruby/jruby-1.1.5/lib/ruby/1.8/mkmf.rb:1:in `require'
    from extconf.rb:1
Gem files will remain installed in C:/rubyrepos/jrubygemrepo/gems/rmagick-2.9.1 for inspection.
Results logged to C:/rubyrepos/jrubygemrepo/gems/rmagick-2.9.1/ext/RMagick/gem_make.out

As you would guess, you then need to hunt for an equivalent gem that will work with JRuby. Anything with "pure Ruby" in its description is a good bet. In the case of RMagick, there is a RMagick4j. Some other examples JRuby compatible gems are Mongrel, Hpricot, ImageVoodoo, JRuby-OpenSSL, JRuby/LDap, json_pure, and postgres_pr.

If you are developing with both Ruby and JRuby, you might want to create a separate repository that holds the gems that work for both implementations, and then put that repository into your GEM_PATH. That way, you won't have to install the gem twice. If you are using NetBeans IDE, use the Ruby Platform Manager to add the repository to a platform's GEM_PATH.

If you want to require a certain gem based on whether you are running on JRuby, you can check whether JRUBY_VERSION is defined.

Monday Feb 09, 2009

Installing Your Own JRuby to Use With the NetBeans IDE

The Ruby support for NetBeans includes a bundled JRuby installation. This is great for quickly getting started with the IDE, but I recommend that you download and install your own version of JRuby and use that one instead. There are a few reasons for doing so, one of which is that the next time you install a NetBeans version, you will get a new bundled JRuby installation, most likely a different version. If you have added gems to the old bundled JRuby, you will have to reinstall those gems to the new bundled JRuby.

Another reason is when you want to work with more recent JRuby version. For this reason alone, it is good to learn how to install JRuby and register it with the IDE. Below are the steps that I do to add a JRuby installation.

  1. First download JRuby from the JRuby site and install it by following the Getting Started instructions.

    TIP: If you are downloading the 6RC1 version, after you unpack it, rename the directory from jruby-1.1.6RC1 to jruby-1.1.6. For some reason, The GlassFish app server barfs on the RC1 in the path name.

  2. Put JRuby's bin in your environment path. I remember reading some recommendation that if you have both Ruby and JRuby, put JRuby after Ruby in the path. Because I switch out JRuby versions often, I created a JRUBY environment variable that points to the bin directory of the JRuby that I am working with, and I added the JRUBY environment variable to my path. To test it, I type jruby -v on the command line.

  3. Now you can register your new JRuby installation with the NetBeans IDE. Choose Tools > Ruby Platforms from the main menu. Choose Add Platform, and navigate to and select the JRuby executable in the bin directory. If you are on Windows, this is jruby.bat. Click Open.

  4. This step is optional, and I don't suggest it if you are new to Ruby and installing gems. I get tired of having to install the same gems over and over every time I upgrade JRuby, so I create a separate repository (outside of the installation folder) for the gems. If you want to do this, click the Browse button to the right of the Gem Home text box, type the path to your gem repository, and click Open. (If you don't have one yet, use the New Folder button in the dialog box to create it, such as some-ruby-repo-path/jrubygemrepo. When you click Open, it will ask if you want to set up your repository there, click OK.)

    Next click the Add button to the right of the Gem Path text box and add the repository to the gem path.

  5. You will need the debugger gems. Follow the instructions on the NetBeans Ruby Debugger wiki page. Make sure you get the correct versions -- the ones noted on the wiki page. If you opted for a separate gems repository in the previous step, then add --install-dir your-repo-path to the gem install commands.

  6. Next, I install Rails. You can do this from the command line, or from the IDE's Ruby Gems Manager, which is available from the main menu. When you open the Ruby Gems manager, click the Settings tab and select Fetch All Versions so that you have a choice of which version to download. Then click the New Gems tab and click Reload Gems. Select Rails and click Install. You will be asked to select a version. If you want to follow the 6.5 tutorials, be sure to install Rails 2.1.2 or 2.1.0 because you need Rails 2.1.\* for the tutorials. Version 2.1.1 is not compatible with JRuby.

  7. Some other gems you might want to install right away are jruby-openssl, Active Record JDBC Adapter, and the JDBC adapters for the databases that you use. See Using Database Servers With JRuby for more information about the JDBC adapters.

Hopefully, this is complete enough to get you going. Please add comments if you have suggestions or steps to add.

Tuesday Dec 09, 2008

Our NetBeans Ruby Book is Done!

If you have been wondering why this blog has been so quiet for so long, it is because I was working on a NetBeans Ruby book with Brian Leonard. Brian asked me to help him with the book and I am glad that he did. It was a good experience working with Brian and I am happy with how it turned out.

The book is published by Apress and is available in ebook and hard copy here.

In the book we delve into the details of how to use the IDE to develop Ruby and Ruby on Rails projects. If you haven't tried NetBeans IDE 6.5 yet, I am sure you will find the book helpful from start to finish. For those who are upgrading, the book helps you to learn about the new features. Even if you are an experienced NetBeans user, I bet you will find stuff you don't know, especially in the chapters on using the editor and on customizing the IDE.

We got a lot of help from a lot of people along the way. Foremost were the NetBeans Ruby engineers Erno Mononen and Martin Krauskopf who patiently answered every question. Erno was also the book's technical reviewer. Tor Norbye contributed to the editing chapter, and Nick Sieger helped with the chapters about Warbler and JRuby. When it came to GlassFish, we leaned on Arun Gupta and Peter Williams.

I would also like to thank the frequent posters to the users@ruby.netbeans.org alias, such as Bharat, Anthony, and James, who provided a good user perspective and answered my requests for information about best practices.

Last, I want to show appreciation for my managers Sophia and Dave for their support all the way through the process, and for my husband who took over most of my chores without complaint so I could spend my spare time working on the book.

Monday Jul 07, 2008

How Do I Access Databases From My JRuby Rails Project?

Over the last year, as I wrote and updated the Ruby tutorials, I end up with many different versions of the Rails applications, where each is based on a different version of JRuby. I often test with both Ruby and JRuby, and I try to test them using different database servers. Rather than follow a tutorial from scratch to get a working version for my current configuration, I wanted to learn how to easily take an application and change it to work with a different database configuration. For example, how can I take an application that I developed using the native Ruby interpreter, and make it work using the JRuby interpreter, or take an MySQL application and use it with a PostgreSQL server. As I researched the history of JRuby access to databases, I compiled my notes into a FAQ, which I posted to wiki.netbeans.org/FaqRailsJRubyDatabaseAccess.

Hopefully, you will find it helpful. If not, post a comment as to what other information you would like to see, or let me know when the instructions don't work. Even better, you can correct the FAQ itself if you have joined the NetBeans community.

Tuesday Nov 13, 2007

Getting Your Feet Wet With Java in JRuby

If you haven't tried calling Java classes from a JRuby application yet, here is a simple code snippet to get you started. Paste the following code into the Ruby shell (JRuby IRB), press Enter, and a small desktop app opens (To open the Ruby shell in the NetBeans IDE, choose Ruby > Other > Ruby Shell (IRB) from the main menu). This code is an updated version of an example in the JRuby and the Java Platform article.

Note: A current known bug causes the JRuby IRB to report an ExitSecurityException, this bug does not affect the output.

Code Sample: Using Java Classes in the IRB Console
include Java

import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JButton
import java.awt.BorderLayout

frame = JFrame.new
panel = JPanel.new
panel.layout = BorderLayout.new
panel.background = java.awt.Color::white
frame.get_content_pane.add(panel)
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
button = JButton.new "Click Me"
text = JLabel.new "I'm a Simple Program"

panel.add(BorderLayout::CENTER, text)
panel.add(BorderLayout::SOUTH, button)

class Click
    include java.awt.event.ActionListener

    def initialize(button, text)
        @button, @text = button, text
        @click_me_mode = true
    end

    def actionPerformed(event)
        source = event.source
        if (source == @button)
            if (@click_me_mode)
                @text.text = "Button Clicked"
                @button.text = "Click Again"
                @click_me_mode = false
            else
                @text.text = "I'm a Simple Program"
                @button.text = "Click Me"
                @click_me_mode = true
            end
        end
    end
end

button.add_action_listener(Click.new(button, text))
frame.title = "Example"
frame.pack
frame.visible = true 

The IRB is a nice way to test out your code. However, with the NetBeans IDE, it is just as easy to test out code in a scratch program. To see what I mean, right-click in the NetBeans Projects window and choose New > Project. In the New Project wizard, select Ruby in the Categories pane, select Ruby Application in the Projects pane, and click Next. Name the project Scratch (or whatever you want) and click Finish. The main.rb file opens in the editor.

Replace the contents of the main.rb file with the code sample. Then click the Run Main Project button in the main toolbar (the green arrow) to run the application.

As you can see by the following screenshot, the advantage of testing your code in a scratch project as opposed to using the IRB is that you get syntax coloring and all the other wonderful NetBeans Ruby editing features.

To learn about the editing features, see the NetBeans Ruby Editing wiki page, or look at Tor's screenshot of the week entries, such as Ruby Screenshot of the Week #18: Errors and Snippets (as of today, he is up to screenshot #23). We are also working on a getting started guide that will cover some of the editing features. Last, you can watch Roman's Editing screencast.

There are a couple of FAQs that you might find helpful

  1. How to Call Java From Ruby
  2. How Can I Access Java From the JRuby IRB?

You also might want to check out the Swing with JRuby: Developing a Desktop Application with the JRuby and Java Swing APIs tutorial that was written by Sun campus ambassador Teera Kanokkanjanarat.

Monday Oct 29, 2007

Community-Contributed NetBeans Ruby Docs

In this blog, we would like to acknowledge two NetBeans Ruby community-contributed tutorials:

Thanks to Teera and Amit, we have a richer documentation set, which you can view in its entirety on the NetBeans Ruby Tutorials and Screencasts page.

If you are interested in contributing documentation to the NetBeans Community, consider joining the dev@userguide.netbeans.org email alias. This alias is for community members who want to not only contribute documentation but also provide input and feedback regarding existing NetBeans documentation. You can sign up for the alias as follows:

  1. Go to the NetBeans Mailing Lists Page
  2. Log on with your user name. If you don't have a user name, click Login and then register for a login name.
  3. Scroll to the dev@usersguide.netbeans.org mailing list.
  4. Click subscribe to send a subscription request.

Monday Oct 15, 2007

Chart for NetBeans Ruby Database Access Setup

I have written both an installation and configuration article and an accessing databases FAQ for projects built using NetBeans Ruby support. However, because there are lots of different configuration paths, and each path requires some in-depth information, neither of these documents make it easy to quickly figure out what you must do to set up your Rails project to access your database server. I created this chart to hopefully make the steps simpler, and more clear. If you need more details, then consult the two documents that I mention above.

Steps for Accessing Databases Using NetBeans Ruby Support
 
Using JRuby
 
Using MySQL
 
   Using JDBC
Do:  Put the MySQL JDBC 3.0 compliant driver in netbeans-install-dir/ruby1/jruby-1.0.1/lib.
Do:  Select the database server from the drop-down list in the New Project wizard.
Do:  Select the Access Database Using JDBC checkbox in the New Project wizard.
 
  Using the Bundled MySQL Adapter
Do:  Select the database server from the drop-down list in the New Project wizard.
Do:  Clear the Access Database Using JDBC checkbox in the New Project wizard.
 
Not Using MySQL
   Do:  Put database's JDBC 3.0 compliant driver in netbeans-install-dir/ruby1/jruby-1.0.1/lib
Do: Select the database server from the drop-down list in the New Project wizard.
Do: Select the Access Database Using JDBC checkbox in the New Project wizard.
Notes: Currently, the supported databases are: MySQL, PostgresSQL, Oracle, HSQLDB, and Java DB (also known as Derby). The database's JDBC driver must be a pure Java driver. If you are deploying to GlassFish, you must also put a copy of your database server's JDBC driver in glassfish-install-dir/lib and start (or restart) the GlassFish server.

 
Using Native Ruby
 
Using MySQL
  
Using the Bundled MySQL Adapter
   Do:  Select the database server from the drop-down list in the New Project wizard.
Do:  Clear the Access Database Using JDBC checkbox in the New Project wizard.
  
Using a MySQL Gem
   Do:  Consult Ruby on Rails MySQL page. Download and install appropriate software.
Do:  Select the database server from the drop-down list in the New Project wizard.
Do:  Clear the Access Database Using JDBC checkbox in the New Project wizard.
  
Not Using MySQL
   Do:  Consult the Ruby on Rails Database Drivers page. Download and install appropriate software.
Do:  Select the database server from the drop-down list in the New Project wizard.
Do:  Clear the Access Database Using JDBC checkbox in the New Project wizard.
All
   Do:  Edit database.yml to specify username, password, and, if necessary, database name.

Wednesday Sep 26, 2007

Using jMaki 1.0 With NetBeans Ruby

The jMaki 1.0 framework, with support for Java, PHP, and Ruby, was released yesterday. Last week, Arun Gupta posted a screencast showing how to use jMaki wrappers of button and table widgets from Dojo and Yahoo frameworks in a Ruby on Rails application built using the NetBeans 6.0 Beta IDE.

With Arun's permission, I am supplying the steps to recreate a similar jMaki on Rails project. To save steps, I changed the order a bit. If you don't already have NetBeans Ruby Support, go to the Installing and Configuring Ruby Support tutorial for instructions.

  1. Before you begin, create the database for this Rails application. You need a database server that is supported by JRuby, such as MySQL, Java DB, PostgresSQL, Oracle, or HSQLDB. Add a database instance named rorjmakitables_development. For example, for MySQL, start the server and type the following at a command prompt.
    mysqladmin -u root -p create rorjmakitables_development
    If you don't need a password, omit the -p.

  2. If you haven't already, download the jMaki NetBeans plugin (This is org-netbeans-modules-sun-jmaki.nbm. The installer tells me it is version 1.6.11, and the info.xml in the NBM says its release date is Sept. 25, 2007).

  3. To install it into the IDE, complete the following steps:

    1. In the IDE, choose Tools > Plugins from the main menu.

    2. Click the Downloaded tab and click Add Plugins.

    3. Navigate to and select the downloaded org-netbeans-modules-sun-jmaki.nbm module, then click Open.

    4. Click Install, and click Next.

    5. Select the radio button to accept the license agreement and click Install.

    6. Select Restart IDE Now and click Finish.

  4. To create a new Ruby on Rails project, complete these steps:

    1. Right-click on a blank spot in the Projects window, and choose New Project from the pop-up menu.

    2. Select Ruby in the Categories pane, select Ruby on Rails Application in the Projects pane and click Next.

    3. If you have other Ruby installations in your path besides the bundled JRuby installation, you are asked to choose a Ruby interpreter. This dialog only pops up the first time the IDE needs to access the interpreter. For this tutorial, choose JRuby and then click Close. Note that this choice affects all Ruby projects. You can switch this setting whenever you want. See Installing and Configuring Ruby Support to learn how.

      If you have configured the IDE to not use JRuby, please use the Options wizard to switch back to JRuby for this tutorial, as described in Installing and Configuring Ruby Support.

    4. Type rorjmakitables, and accept the default location or, optionally, enter a different path.

    5. Choose a Database from the drop-down list. Your choice specifies how to set up the database.yml file. This tutorial uses MySQL.

      At the time of this writing, Java DB is not on the list, but it probably will be added later. So, if you are using the Java DB, and you don't see it on the list, don't bother selecting a database. You can edit the database.yml file instead. See Using Database Servers With JRuby for instructions.

    6. With JRuby, if you don't use MySQL, you must select the Access Database Using JDBC checkbox. This causes the project to modify the environment.rb configuration file to use the ActiveRecord-JDBC gem. So, unless you are using MySQL, check this box.

    7. Click Next.

    8. Because you are using the bundled JRuby, which includes Rails, the wizard shows that Rails is already installed. The wizard gives you the option of updating the installed version, but let's skip that.

      Click Finish.

      The Generate Rails Project tab in the Output window shows all the folders and files that the IDE creates.

  5. The IDE opens the database.yml file in the editor. Set the username for the development configuration, as shown below. If your database requires a password, set the password too.
      development:
      adapter: mysql
      database: rorjmakitables_development
      username: root
      password: root_password
      host: localhost
    
  6. To add a controller, right-click the rorjmakitables project node in the Projects window, and choose Generate. Select controller from the Generate drop-down list, set the Name to say and set the View to table, then click OK.

  7. In the Projects window, expand Configuration and double-click routes.rb to open it in the editor.

  8. Add the following line above all the other map.connect entries.
      map.connect '', :controller => 'say', :action=>'table'
    
  9. In the Projects window, expand Public, right-click index.html and choose Delete (or Rename if you would rather rename the file).

  10. In the Projects window, expand Views, expand say, and double-click table.rhtml to open it in the editor.

  11. On the right-side of the IDE is the Palette, as shown below. Expand jMaki Yahoo.



  12. Drag a Button widget from the jMaki Yahoo section and drop it on the file.

  13. Drag and drop a second Button widget.

  14. Replace the widget code fragments with the following code.
    <%= jmaki_widget 'yahoo.button',
      :value => { :label => 'Select 1',
      :action => { :topic => '/jmaki/table/select',
        :message => { :targetId => '1' }
      }
    } -%>
    <%= jmaki_widget 'yahoo.button',
      :value => { :label => 'Select 2',
      :action => { :topic => '/jmaki/table/select',
        :message => { :targetId => '2' }
      }
    } -%>
    
    These buttons use the jMaki publish/subscribe mechanism to publish to the /jmaki/table/select topic, which you will program two table widgets to listen to. The table widgets will select either the first row or the second row, depending on which button is clicked. For more details on how to use publish/subscribe, see Carla Mott's Widgets Talking To Widgets blog entry.

  15. Drag a Data Table widget from the jMaki Yahoo section onto the file.

  16. Expand jMaki Dojo and drag a Table widget from that section onto the file.

    Both these widgets use the jMaki Table Data Model.

  17. Add :subscribe=> "/jmaki/table", to each table widget, as shown in bold below, to make both tables listen to all the /jmaki/table topics.

    (Important)Also, change the row data to include numeric ids, as shown in bold, so that they match the target ids in the button code. For the first row, you have to add :id= > '1',. For the second row, which already has the :id argument, simply change bar to 2.
    <%= jmaki_widget 'yahoo.dataTable', :subscribe=> "/jmaki/table",
      :value =>
      {:columns => [
        { :label => 'Title', :id => 'title'},
        { :label => 'Author', :id => 'author'},
        { :label => 'ISBN', :id => 'isbn'},
        { :label => 'Description', :id => 'description'}
      ],
      :rows => [
        { :id=> '1', :title => 'Book Title 1', 
              :author => 'Author 1', :isbn => '4412', 
              :description => 'A Some long description'},
        { :id => '2', :title => 'Book Title 2', 
              :author => 'Author 2', :isbn => '4412', 
              :description => 'A Some long description'}
      ]
    }
    -%>
    <%= jmaki_widget 'dojo.table', :subscribe=> "/jmaki/table",
      :value =>
      {:columns => [
        { :label => 'Title', :id => 'title'},
        { :label => 'Author', :id => 'author'},
        { :label => 'ISBN', :id => 'isbn'},
        { :label => 'Description', :id => 'description'}
      ],
      :rows => [
        { :id=> '1', :title => 'Book Title 1', 
              :author => 'Author 1', :isbn => '4412', 
              :description => 'A Some long description'},
        { :id=> '2', :title => 'Book Title 2', 
              :author => 'Author 2', :isbn => '4412', 
              :description => 'A Some long description'}
      ]
    }
    -%>
    
  18. Click the Run Main Project button on the main menu (the green arrow). This starts the server and opens the table view in a browser.

  19. Click the first button to select the first row, and click the second button to select the second row.

  20. In order to display database data in the table, we must first create a model. In the Projects window, right-click the project node, and choose Generate from the pop-up menu.

  21. Choose model from the Generate drop-down list, type grid in the Arugments text box, and click OK.

  22. To define the model's data structure, expand Data Migrations in the Projects window, then expand migrate and double-click 001_create_grids.rb to open it in the editor.

  23. Replace the up method with the code shown in bold.
    class CreateGrids < ActiveRecord::Migration
    
     def self.up
        create_table :grids do |t|
          t.column :title, :string
          t.column :author, :string
          t.column :isbn, :string
          t.column :description, :string
        end
        Grid.create(:title=> 'Marathon',
           :author=> 'Jeff Galloway',
           :isbn=> '0936070250',
           :description => 'A running book for everybody');   
        Grid.create(:title=> 'The Runners Bible',
           :author=> 'Marc Bloom',
           :isbn=> '0385188749',
           :description => 'How to train, race, and get in shape');   
      end
    
      def self.down
        drop_table :grids
      end
    end
    
  24. To create the database table and populate it with the two rows of data, right-click the project node in the Projects window and choose Migrate Database > To Current Version from the pop-up menu.

  25. Now you can define a variable that contains the data from the database table. In the Projects window, expand Controllers and double-click say_controller.rb to open it in the editor.

  26. Replace the table definition with the following code shown in bold.
    class SayController  < ApplicationController
    
      def index
        table
        render :action => 'table'
      end
     def table
        @rows_data = []
        Grid.find_all().each do |data|
          @rows_data  << { :id => data.id,
            :title => data.title,
            :author => data.author,
            :isbn => data.isbn,
            :description => data.description
          }
        end
      end
    end
    
    The above code defines the rows_data variable and initializes it to an empty array. It uses the active record to find all the rows from the database and, for each row, add a hash of the fields to the rows_data array.

  27. Return to the table.rhtml view by right-clicking in the editor and choosing Navigate > Go To Rails Action or View.

  28. Replace the static rows data in the table fragments with the @rows_data variable as shown in bold below.
    <%= jmaki_widget 'dojo.table',
    :value =>
    {:columns => [
         { :label => 'Title', :id => 'title'},
         { :label =>'Author', :id => 'author'},
         { :label => 'ISBN', :id => 'isbn'},
         { :label => 'Description', :id => 'description'}
         ],
      :rows => @rows_data
      }
    -%>
    <%= jmaki_widget 'yahoo.dataTable',
    :value =>
    {:columns => [
         { :label => 'Title', :id => 'title'},
         { :label => 'Author', :id => 'author'},
         { :label => 'ISBN', :id => 'isbn'},
         { :label => 'Description', :id => 'description'}
         ],
      :rows => @rows_data
      }
    -%>
    
  29. Choose File > Save All from the main menu to save all your changes.

  30. Go back to the browser and refresh the page. The data now comes from the database table.

There you have it! To learn more about jMaki, go to www.jmaki.com. To learn more about NetBeans support for Ruby, go to wiki.netbeans.org/wiki/view/Ruby.

Monday Sep 17, 2007

Arun Pushes the Edge of the JRuby/GlassFish Envelope

Last week, Arun Gupta paid a visit to the NetBeans Ruby writers. It was great to finally meet this dynamo in person and find out what a nice guy he is. When we first started writing about NetBeans Ruby, we used Arun's blog Miles to Go as one of our resources to quickly learn about the technology. Arun tells us that the blog's name has a double meaning: he is both an avid runner and he feels like he has a lot to learn in his job.

In addition to Ruby/JRuby and GlassFish, Arun blogs on a variety of topics, including jMaki, web services, WSIT, Ajax, and Web 2.0. Arun somehow manages to be one of the first to write about how to use emerging technologies, so we like to keep an eye on his blog to find out what we will be writing about in the future. For example, last Friday, he blogged about a new GlassFish gem for Rails. We also like to follow his popular "Tip of the Day" entries. You will often see his information folded into our tutorials. Arun seems to really understand his audience's information needs and he has been very helpful by providing good suggestions as to what to include in our tutorials.

Wednesday Sep 12, 2007

Native Ruby and JRuby Support in NetBeans IDE 6.0

There is a rumor floating around that the NetBeans IDE Ruby support only works for JRuby. Don't believe it. The IDE makes it very easy to use your own Ruby installation in addition to the bundled JRuby software. As a matter of fact, the first time that you open or create a Ruby project, the IDE looks on your system for other Ruby installations. If it finds any, it pops up a dialog box listing the available installations and lets you choose which one to use.

Using JRuby is just like using Ruby, and you don't have to know anything about Java to use JRuby. You can open your existing Ruby applications for development in the IDE and work with them using the IDE's features regardless of whether you have chosen to use the JRuby interpreter or your native Ruby interpreter. The one exception that I know of is that with JRuby you have to use the ActiveRecord-JDBC adapter if you are using a database server other than MySQL. However, all you have to do is to put the client driver in JRuby's lib folder, make a couple of simple changes to your database.yml, and add a snippet to your environment.rb. Tom Enebro writes about it here. The ActiveRecord-JDBC adapter works with MySQL, Postgresql, Oracle, Derby/Java DB, HQLSDB, and H2 database management systems.

One of the advantages of using JRuby is that you can access Java libraries from your Ruby application. Tor and Cindy put together a great video about this for NetBeans TV.

Another benefit is that you can war up a JRuby application and deploy it to a Java application server, such as GlassFish, just like you would with a Java web application. Arun Gupta has written several blog entries about this and the upcoming Installing and Setting Up Ruby tutorial provides step-by-step instructions for one of the simpler methods of deploying to the GlassFish server. One advantage of deploying to Java application servers is that they are designed to be multi-threaded and thus can handle more than one request at a time. In addition, Java application servers provide tools that make it easier to manage your deployed applications. For detailed information about creating and deploying JRuby applications, see the Rails Integration page on the JRuby wiki.

About

divas

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  
       
Today