Installing and Configuring Ruby Support
Contributed by Chris Kutler Maintained by the NetBeans Documentation team
June 2010
This document provides information about downloading, installing, and configuring Ruby support in
NetBeans IDE 6.9
Contents
Downloading Ruby Support
If you do not have NetBeans 6.9 IDE installed, go to
the NetBeans IDE
Download Page and download either the Ruby bundle or the All
bundle.
If you already have NetBeans IDE 6.9 installed, but it does not include Ruby support,
complete the following steps to add Ruby support to the IDE.
If you are not sure whether the IDE has Ruby support, select File
> New Project from the main menu. If you see Ruby in the Categories
list, Ruby support is installed.
- 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.
- Choose Tools > Plugins from the main menu.
-
In the Plugins dialog box, click the Available Plugins tab, scroll to the Ruby category.
- Select the Ruby and Rails checkbox to obtain Ruby support for the NetBeans IDE.
(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.
(Optional) Select the following plugin:
- Extra Ruby Color Themes. Provides additional editor
color themes for the Ruby file types.
Click Install.
The NetBeans IDE Installer appears.
- In the NetBeans IDE Installer, click Next.
- Read the license agreement, then select the I Accept the Terms in All
License Agreements option and click Install.
- After the installation is complete, 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.
In the IDE, choose Tools > Ruby Platforms from the main menu.
The Ruby Platform Manager appears, as shown in the
following figure.
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.
- Click OK to close the Options dialog box.
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.
- New Gems. Lists the gems that you can add to the selected Ruby platform. To narrow the list,
type a search string into the Search text box. The IDE narrows the list as you type. By default, the IDE
lists only the most current versions of the gems, and excludes a gem from the list if you have already
installed that version. If you want to see all versions, select the Fetch All Gem Versions checkbox in the Settings
tab.
- Settings. Use this tab to configure the proxy and to configure the following options. When you enable these options,
it takes the IDE longer to gather and display the gem lists.
-
Fetch All Gem Versions. Select this checkbox to list
all available gem versions.
-
Fetch Detailed Gem Description.
Select this checkbox to load detailed descriptions for each gem.
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.
Using Database Servers With JRuby
You can access databases from a JRuby on Rails application in
one of three 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. If you do not enter
any information in Step 3 (Database Configuration)
of the New Project wizard, this
is the setting that the IDE uses. Do not select the
Access Database Using JDBC checkbox if you use this adapter.
JDBC Adapter. 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(R), HSQLDB, and Java DB (also known as Derby).
The JDBC driver must be a pure Java 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 Development Kit (JDK) 6.0, the IDE automatically
registers the Java DB database server with the IDE.
If you are running your application on the GlassFish
V3 Server, you must also copy the driver to the
lib folder of the project's JRuby installation and
then restart the server. If you are not sure of the location
of the JRuby installation, right-click the project's node
and choose Properties from the pop-up menu. Click Manage.
The Ruby Platform Manager appears, which shows the path
to the JRuby installation.
- JDBC Adapter for Your Database Server.
Several JDBC adapter gems
are written for database servers. These gems include
the JDBC 3.0 compliant drivers. For example, you can install and
use the following gems.
-
H2. activerecord-jdbch2-adapter
-
HSQLDB. activerecord-jdbchsqldb-adapter
-
Java DB/Apache Derby. activerecord-jdbcderby-adapter
-
MySQL. activerecord-jdbcmysql-adapter
-
PostgreSQL. activerecord-jdbcpostgresql-adapter
-
SQLite3. activerecord-jdbcsqlite3-adapter
To use one of these adapters, edit the adapter settings
in the database.yml
file under the Configuration node. Use the middle portion
of the gem name for the adapter setting. For example, set the adapter
to jdbcmysql for the MySQL database. Do not select
the Access Database Using JDBC checkbox when you use these adapters.
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 occur.
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:
Running JRuby Applications on the
Integrated GlassFish Server Open Source Edition 3.0.1
The GlassFish Server Open Source Edition 3.0.1 application server is included with the Ruby bundle and is the default server for JRuby on
Rails applications.
When you run your Rails applications using the GlassFish server, the URL will be different
than if you run with WEBrick or Mongrel. The port is 8080 and you include project name in the URL. If
you do not want the project name in the URL, perform the following steps.
-
In the Services window, expand Servers.
-
Right-click the GlassFish Server Open Source Edition 3.0.1 node and choose Properties from the pop-up menu.
-
Click the JRuby tab.
-
Select Deploy All Rails Applications at Root Context.
Note: Choosing not to include the project name in the URL can cause
problems. If you have more than one Rails application deployed to the server, and the applications
have the same routes, the server might access the wrong route.
The JRuby platform that the GlassFish server uses to run your application depends on how the server was started.
If the server is not running when you run your application, the server uses the application's JRuby platform. Otherwise
it uses the platform that the server was started with. If no platform is specified when the server is started, it uses the Default
JRuby Platform that is specified in the JRuby tab in the server's Properties dialog box.
Because SQLite reads and writes directly to and from the database files on disk, if the application uses SQLite, you must
edit the database.yml file to specify the full path to the database, such as
database: /usr/local/sqlite/var/rubyweblog_development.sqlite
The IDE does not pass the Rails Environment setting in the Project Properties dialog box to the GlassFish
server. This might change in a patch or future release.
If you need to run the application in a different
mode on the GlassFish server, such as
production mode, uncomment and modify the following
statement in the environment.rb file. In order for the
change to occur, you must either undeploy the
application or restart the server. You can do both of
these actions from the Servers node in the Services
window.
# ENV['RAILS_ENV'] ||= 'production'
Note:
Your test suites might not work correctly if you
run them while RAILS_ENV is set to production mode.
Deploying a JRuby Application to
an Application Server
The IDE provides integration with the Warbler plugin. When you
create a Rails project, you can select
Add Rake Targets to Support App Server Deployment to add the Warbler
plugin and war Rake tasks to the project. If you haven't installed
the Warbler gem for the project's platform yet, the New Project wizard
takes you to the final step where you can click a button to install
the Warbler gem.
If you want to add the Warble plugin to an existing project,
install the Warble gem if it is not already installed. Then
open a terminal window, change the directory to the root of the
project and type the following command.
jruby -S warble pluginize
When you are ready to deploy the application, open the database.yml file to ensure that the
production configuration is set correctly. Then use the war Rake task
to generate a WAR file, and deploy that file to the desired application
server.
For more information about using Warbler, go to warbler.kenai.com.
Next Steps
>> More Ruby Documentation