How to Work with JRuby in the NetBeans IDE

May

In this tutorial, you will convert JRuby to a NetBeans project and learn how to build and perform test-runs of JRuby projects in the NetBeans IDE.

Introduction

JRuby is a 100% pure Java implementation of the famous Ruby programming language, which is a dynamic, open-source language focused on simplicity and productivity. Ruby has an elegant syntax that is natural to read and easy to write.
This tutorial shows you how to use the NetBeans IDE for JRuby development.

The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications. In this tutorial, you learn how to convert a JRuby project to a Netbeans project to develop, build, and test JRuby within the Netbeans IDE.

For more information on how to work with the NetBeans IDE, see the Support and Docs page.

Software needed

Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0.
Since NetBeans 6.0 is under development now, use NetBeans IDE 6.0 Preview (M9) available from NetBeans IDE 6.0 Preview (M9) Download or check the latest working version.

Notations used in this documentation

  • <NETBEANS_HOME> - the NetBeans IDE installation directory
  • <USER_HOME> - the user's home directory. Example: "C:\Documents and Settings\user_home"
  • <jruby_src_root> - directory with the JRuby sources.

Exercises

You can check out a JRuby release as a NetBeans project from the JRuby repository.

However, if you use a publicly available version, you can perform the following steps to convert your existing JRuby into a Netbeans Project.

Converting JRuby to a Netbeans Project

Download JRuby Sources:

1. Download the JRuby source code.

2. Extract the files from this archive to the <jruby_src_root> directory.

3. Replace ant.jar located in the <jruby_src_root>/lib directory with ant.jar version 1.6.5 or newer.

This step is required because of the following JRuby's known bug: "The existing ant.jar is an old 1.5 version."

Creating the JRuby NetBeans Project:

1. From the main menu, choose File > New Project.
The New Project wizard opens.

2. In the Categories list, select "Java Project with existing ANT Script" and click Next.

3. At the Name and Location page, specify the locations of JRuby's project files and the build.xml file. In our case, the JRuby project files are at C:\tmp\jruby-0.9.8.

Click Next.

4. At the Build and Run Actions page, specify the following ant targets in the fields listed below:

  • Build Project - jar
  • Clean Project - clean
  • Generate Javadoc - create-apidocs
  • Run Project - leave this field empty
  • Test Project - test

Click Next.

5. At the Source Package Folders page of the wizard, specify <jruby_src_root>/src as the source package folder and <jruby_src_root>/test as the test package folder.

Click Next.

6. At the Java Sources Classpath page, add all .jar files and folders under the <jruby_src_root>/lib directory to the Java Sources Classpath list.

7. Select the test source package folder and add the bsf.jar, and junit.jar files under the <jruby_src_root>/lib directory and the src folder to the Java Sources Classpath list.

Click Finish.

The Projects window contains a project node for JRuby you have just created. Now you can develop JRuby within the NetBeans IDE.

Building the JRuby Project

To build a jruby.jar, do the following:

1. In the Projects window, right-click the JRuby project node and choose Build Project or Clean and Build Project from the pop-up menu.

The JRuby .jar file will be built and you will see the "BUILD SUCCESSFUL" message in the Output window.

Testing the JRuby Project

To perform testing of the JRuby project, do the following:

1. In the Projects window, right-click the JRuby project node and choose Test Project from the pop-up menu, or press Alt+F6.

A test run of the JRuby project is performed and you see test results in the JUnit Test Result and Output windows.

Summary

In this tutorial, you learned how to start JRuby development in the NetBeans IDE. You have completed the following exercises:

  • Convert JRuby into Netbeans Project.
  • Build JRuby in NetBeans IDE.
  • Test JRuby in NetBeans IDE.

See Also

Attachments

build-pr.jpg Info on build-pr.jpg 50142 bytes
building-jruby.jpg Info on building-jruby.jpg 114317 bytes
building-jruby1.jpg Info on building-jruby1.jpg 114317 bytes
folder-structure.jpg Info on folder-structure.jpg 57267 bytes
open-jrubynb.jpg Info on open-jrubynb.jpg 31705 bytes
project-actions.JPG Info on project-actions.JPG 40729 bytes
project-actions.jpg Info on project-actions.jpg 40729 bytes
project-classpath-src.jpg Info on project-classpath-src.jpg 63169 bytes
project-classpath.JPG Info on project-classpath.JPG 63169 bytes
project-classpath.jpg Info on project-classpath.jpg 52415 bytes
project-existing-ant.JPG Info on project-existing-ant.JPG 46071 bytes
project-existing-ant.jpg Info on project-existing-ant.jpg 46071 bytes
project-source.JPG Info on project-source.JPG 53642 bytes
project-source.jpg Info on project-source.jpg 53642 bytes
test-pr.jpg Info on test-pr.jpg 49478 bytes

NetBeans