FeaturesPluginsDocs & SupportCommunityPartners

Installing and Configuring Ruby Support

Contributed by
April 2008
[Revision number: V6.1-1]

This document provides information about downloading, installing, and configuring Ruby support in the NetBeans IDE.

Contents

Content on this page applies to NetBeans IDE 6.1

Downloading Ruby Support

If you do not have the NetBeans 6.1 IDE, installed, go to the NetBeans IDE 6.1 Download Page, and download a version of the IDE that contains Ruby support. If you have a NetBeans IDE 6.1 installation that does not include Ruby support, complete the following steps to add Ruby support to the IDE.

  1. If your network uses a proxy, choose Tools > Options from the main menu, select Manual Proxy Settings, type the HTTP Proxy and Port for your proxy, and click OK.
  2. Choose Tools > Plugins from the main menu.
  3. In the Plugins dialog box, click the Available Plugins tab, and scroll to the Ruby category, as shown next.

    Selecting Ruby Plugins
  4. Select the Ruby and Rails checkbox to obtain Ruby support for the NetBeans IDE.
  5. (Optional) Select the JRuby and Rails Distribution checkbox to download and install the JRuby software and the Ruby on Rails framework.

    Note: You must have either Ruby or JRuby software installed on your system to use the Ruby and Rails distribution. If you do not have this software, you must either install this plugin, or download and install JRuby or Ruby software before working with Ruby projects in the IDE.

  6. (Optional) Select one or more of the following plugins:

    • Extra Ruby Color Themes. Provides additional editor color themes for the Ruby file types
    • Ruby Extra Hints. Provides code hints for Ruby that were developed after the last release of the IDE
    • GlassFish V3 JRuby Integration. Enables you to install Glassfish V3 instances into the IDE, and to configure an instance as the current server in a Ruby on Rails Project
  7. Click Install.

    The NetBeans IDE Installer appears.
  8. In the NetBeans IDE Installer, click Next.
  9. Read the license agreement, then select the I Accept the Terms in All License Agreements option, and click Install.
  10. After the installation is completed, select either Restart IDE Now or Restart IDE Later and click Finish.

Configuring the IDE to Use Your Own Ruby Installation (Optional)

When first installed, the Ruby and Rails module registers any Ruby installations that it detects on your system. To add additional Ruby or JRuby installations, complete the following steps.

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

    The Ruby Platform manager appears, as shown in the following figure.

    Platform Manager
  2. Perform one of the following steps to add additional Ruby or JRuby platforms.

    • Click Autodetect Platforms to have the IDE automatically detect and add the platforms that are installed on your system.
    • Click Add Platform to add a specific platform, then navigate to and select the Ruby binary, and click Open.
  3. Click OK to close the Options dialog box.

For information about obtaining Ruby software, see www.ruby-lang.org, instantrails.rubyforge.org, and locomotive.raaum.org.

Managing Gems

Gems are third-party Ruby libraries. The IDE provides a Ruby Gems manager for adding and maintaining gems. You open the Ruby Gems manager by choosing Tools > Ruby Gems from the main menu. The manager contains the following tabs:

  • Updated. Lists which of the platform's installed gems have a newer version available.
  • Installed. Displays a list of the gems that have been installed for the selected Ruby platform. See the previous section for information about registering Ruby platforms with the IDE. If you are using the bundled JRuby platform and the IDE includes the JRuby and Rails Distribution plugin, the list contains the ActiveRecord JDBC Adapter gem and the Rails framework, as shown in the next figure.
  • New Gems. Lists the gems that you can add to the selected Ruby platform.
  • Settings. Use this tab to configure the proxy.
 Installed tab in Ruby Gems manager

Note: The RubyGems wiki page provides information about how to enable the Ruby Gems manager to manage a native Ruby gems repository.

For more information about Ruby Gems, go to www.ruby-lang.org/en/libraries/. For more information about Rails, go to rubyonrails.org. Information about the ActiveRecord JDBC Adapter gem can be found at jruby-extras.rubyforge.org/activerecord-jdbc-adapter/.

Using Database Servers With JRuby

You can access databases from a JRuby on Rails application in one of two ways.

  • MySQL Adapter. The MySQL adapter is included with JRuby. You use this adapter just as you would with a native Ruby on Rails application.
  • JDBC Adapter. As mentioned earlier, the JRuby and Rails Distribution plugin includes the ActiveRecord JDBC Adapter gem, which enables your JRuby on Rails application to access database servers that provide JDBC 3.0 compliant drivers, such as MySQL, PostgreSQL, Oracle, HSQLDB, and Java DB (also known as Derby). The JDBC driver must be a pure Java driver. At the time of this writing, the ActiveRecord JDBC Adapter does not work with the SQLite JDBC driver.

    To use the JDBC adapter in a Ruby on Rails project, select the Access Database Using JDBC checkbox in the Database Configuration step when you create the project, as shown in the next figure.

    If you are using the MySQL or PostgreSQL database server, the IDE automatically adds the bundled driver to the JRuby classpath. For other database servers, the IDE automatically adds the driver to the JRuby classpath if you have registered the database server with the IDE. Otherwise, you must obtain a JDBC 3.0 driver for your database server and add the driver to the JRuby classpath. To add the driver to the classpath, right-click the project's node, choose Properties from the pop-up menu, select the Java category, and click Add JAR/Folder.

    Note: If the GlassFish server is registered, or if the IDE is configured to use Sun Microsystems, Inc. Java SE Development Kit (JDK) 6.0, the IDE automatically registers the Java DB database server with the IDE.

    Selecting JDBC Database Access

When you create a Ruby on Rails project, the IDE adds the configurations to the database.yml for the database server that you select in the Database Configuration step of the Wizard. If you are using a database server that is not in the drop-down list, you can edit the database configuration in the database.yml file after you create the project.

Note: If your operating system's host file does not contain localhost, change the host setting in the configuration to 127.0.0.1. If errors occur when you access the database from Rake commands or database migration commands, try changing the host configuration to fix the problem. You must restart the server for the change to take effect. Note also that with some systems, the database setting must be in lowercase letters.

Note: The Run Rake Task > db > create menu option works only for MySQL, PostgreSQL, SQLite, and SQLite3 adapters. For other database server adapters, including the JDBC adapter, use one of the following steps to create the database:

  • Manually create the database from a command window using the commands that are appropriate for the database server. For example, you would use a command similar to the following to create a MySQL database.
    mysqladmin -u fred -p create mydb_development
    
  • Click the Create DB button for the appropriate configuration in the Database Configuration panel of the New Project Wizard.
  • In the Services window, expand Databases, then right-click the database servers node and choose Create Database from the pop-up menu.

Deploying a JRuby Application to GlassFish

By default, your JRuby applications run in the WEBrick browser. If you want to deploy a JRuby application to the GlassFish application server, you can package the application and its dependencies in a web archive (WAR) file. Then you can make the WAR file available to the application server, as shown in the following steps.

  1. The deployed application uses the production database. Open the database.yml file to ensure that the production configuration is set correctly.
  2. When you create your JRuby application, you are given the option of adding rake targets to support application server deployment, as shown in the following figure. If you intend to deploy to GlassFish, you should select this checkbox.

    Option to Provide WAR Rake Targets

    If you have an existing JRuby project that does not offer this rake target, complete the following steps to add the Goldspike plugin to the project. This plugin adds rake tasks that enable you to create WAR files.

    1. In the Projects window, right-click the project's node and choose Rails Plugins from the pop-up menu, as shown in the following figure.

      Choosing Rails Plugins from the menu
    2. In the Rails Plugins dialog box, click the New Plugins tab.

    3. If you do not see an entry for goldspike, complete the following steps to register the repository that provides the goldspike plugin.

      1. Click the Repositories tab.
      2. Click Add URL.
      3. In the Add Repository URL dialog box, type http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/plugins and click OK, as shown next.

        Typing the URL in the Add Repository URL dialog box
      4. After the repository is added, click Close.

      5. Click the New Plugins tab.

        You should now see an entry for goldspike.

    4. Select the entry for goldspike, as shown in the following figure, and click Install.

      Selecting the entry for goldspike in the New Plugins tab
    5. Click OK to start the installation.

    6. When the installation has succeeded, close both the Installation and the Rails Plugins dialog boxes.

    7. Right-click the rubyweblog project node and choose Run Rake Task > Refresh List from the pop-up menu, as shown next. This choice forces the IDE to recognize the new war rake targets that the Goldspike plugin added to the project.

      Selecting Refresh List from the Run Rake Task menu
  3. To package your application in a WAR file, right-click the project's node and choose Run Rake Task > War > Standalone > Create.

    The IDE creates the WAR file and puts the file in the project's top folder.

  4. Place a copy of the newly created WAR file into the GlassFish autodeploy folder. For example, copy projects-folder/MyRubyApp/MyRubyApp.war to glassfish-install-dir/domains/domain1/autodeploy.
  5. In a browser, go to the URL for the application, for example, http://localhost:8080/MyRubyApp.

Note: If you install the GlassFish V3 JRuby Integration plugin, you can register a Glassfish V3 instance with the IDE, and configure the instance as the current server in a Rails Project. You can then use the Run Main Project button to run the application on the GlassFish V3 instance. Note that all applications are deployed at the root ("/") level, which might cause problems if you are deploying more than one Rails application. This plugin is in the experimental stages of development.

Next Steps


>> More Ruby Documentation

Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by