NetBeans, Solaris, GlassFish: The Ruby's Red Slippers Fit

   
By Janice J. Heiss, Updated August 2008  

Articles Index

Ruby In 2006, Ruby a reflective, dynamic, and interpreted object-oriented language that is officially implemented in free C software, took off, some 11 years after its 1995 release. Here's the story of Ruby, JRuby, and Rails at Sun Microsystems and the larger community.


 

Contents

 
Ruby
Ruby on Rails and the Growth of Ruby
Virtual Machines for Ruby
JRuby
jMaki
Groovy and Grails
Ruby Development Using the NetBeans IDE
Develop-and-Deploy Scenarios
Deploying on Solaris OS AMP
Deploying JRuby on the GlassFish Application Server
Java DB for JRuby Applications
Why Run Rails on GlassFish?
Opening the JVM to Other Languages
 

Ruby

 

Yukihiro MatsumotoMuch admired for its elegance, Ruby was created by Yukihiro Matsumoto from Perl, Smalltalk, Eiffel, Ada, and Lisp in an effort to minimize programmer work and confusion. Matsumoto, known as Matz, remarked that he was trying to "make Ruby natural, not simple," in a way that "mirrors life." Matsumoto created it to be "more powerful than Perl and more object-oriented than Python."

Although Ruby is sometimes described as a scripting language, its supporters characterize it as a general-purpose computer language with broad application.

Ruby is free to use, copy, modify, and distribute -- and highly portable. Although it is most often developed on GNU/Linux or Mac OS X, Ruby works on many types of UNIX, Solaris OS, Microsoft Windows 95/98/Me/NT/2000/XP, and other operating systems. Ruby has recently released version 1.9.0.

Ruby's features include the following:

  • Simple syntax, partially inspired by Eiffel and Ada.
  • Exception handling features designed to make it easy to handle errors.
  • Operators that are syntactic sugar for the methods and are easily redefined.
  • Complete, full, pure object-orientation -- all data in Ruby is an object, in the sense of Smalltalk: no exceptions.
  • Single inheritance.
  • Code blocks -- closures -- are first-class citizens in Ruby and widely used in nearly all Ruby programs.
  • A mark-and-sweep garbage collector that works with all Ruby objects.
  • Dynamically loaded extension libraries if an OS allows.
  • OS-independent threading.

Gems Ruby has been criticized for problems with slow performance, threading difficulties in some scenarios, and lack of native support for Unicode or multibyte strings. Version 2.0 is being designed to address these issues with a new and faster bytecode interpreter, a change from green to native threads, and full support for Unicode strings.

RubyForge is a home for open-source Ruby projects. RubyGems, now part of the standard library from Ruby version 1.9.0, is a package manager for Ruby that provides a standard format for distributing Ruby programs and libraries.

Ruby on Rails and the Growth of Ruby

 

In March 2008, the TIOBE index, which measures the growth of programming languages, ranked Ruby 10th in worldwide popularity, accounting for roughly 2.6% of programmers.

Much of Ruby's growth is tied to the popularity of the open-source Ruby-on-Rails framework, known as Rails, which is used for database-backed web applications based on the model-view-controller (MVC) design pattern.

Ruby on Rails offers skeletal code frameworks to increase speed and ease of development for database web site creation and is popular among younger developers. The speed and agility of Rails has had a significant impact on web development. Rails works with web servers like GlassFish, Apache, Mongrel, and LightTPD, and databases such as MySQL, PostgreSQL, SQLite, Oracle, SQL Server, Java DB, and DB2.

Rails Rails empowers web site construction by analyzing database structures, comprehending table relationships, and automatically creating object-relational mapping code. Developers can then edit, polish, personalize, standardize, apply templates, and make other adjustments as desired. Because it includes all the components of a standard database-backed web application, Rails has been called a "batteries included" framework.

The Rails framework fits well with what publisher Tim O'Reilly calls Web 2.0, which, however defined, refers to such proliferating interactive web sites as Flickr, YouTube, Facebook, MySpace, and others that are characterized by massive information entering the site from the edge of the network. Many future Web 2.0 sites are likely to use Rails, because rapid time to market and reliable maintenance are crucial to the success of Web 2.0. Rails excels in maintainability but can be slow with web applications that require computation.

Virtual Machines for Ruby

Ruby's official implementation, often referred to as Matz's Ruby Interpreter or MRI, after Matsumoto, is the most widely used. It is sometimes referred to as CRuby because it is written in C.

Ruby's popularity has grown beyond its native runtime to VM-based runtimes, with the creation of several other implementations. These include JRuby, a port of Ruby to the Java platform; IronRuby an implementation for Microsoft's .NET framework; Ruby.NET, a compiler that translates Ruby source code into .NET intermediate code for third-party Microsoft platforms only; and Rubinius, an interpreter modeled after self-hosting Smalltalk virtual machines.

YARV, which stands for Yet Another Ruby VM, is a new bytecode interpreter being developed for Ruby, designed to reduce execution time for Ruby programs. With Ruby's 1.9.1 release, due out soon, YARV will become the official Ruby interpreter.

JRuby

 

JRuby JRuby, an open-source Java language implementation of the Ruby language syntax, core libraries, and standard libraries, offers the advantages of Ruby's simple syntax plus interoperability with Java applications -- and the portability, security, and class libraries that come with them.

Originally written by Jan Arne Peterson in 2001, JRuby was further developed by Thomas Enebo and Charles Nutter. Sun Microsystems hired the two developers in September 2006 as JRuby core developers -- evidence of Sun's commitment to JRuby development and openness to the expansion of Java technology for use with other languages.

Thomas Enebo Enebo and Nutter stepped up efforts to supply developers with a wide range of Ruby and JRuby development and deployment scenarios, streamlining the process by providing an all-in-one download solution, which includes tooling in the NetBeans integrated development environment (IDE) and deployment on the Solaris OS.

Ola Bini In addition, Ola Bini, the author of Practical JRuby on Rails and currently a developer at ThoughtWorks Studios, has also made significant contributions to JRuby.

Sun's strategy is tied to the assumption that deployment will follow adoption, and it derives from the belief that businesses will not deploy important applications or solutions without support. As Sun CEO Jonathan Schwartz puts it, "Mindshare gets market share."

Tim Bray"We are actively interested in supporting non-Java technologies such as PHP, Perl, Python, and Rails on our system and OS platforms," says Tim Bray, director of web technologies and Distinguished Engineer at Sun. "While Rails is an excellent framework, Sun is making it faster. Java technology offers first-rate deployment of Rails on GlassFish while NetBeans IDE offers the best Rails and Ruby programmer tools available."

In February 2008, the second release candidate of JRuby 1.1, JRuby 1.1 RC 2, was released.

Charles Nutter "JRuby is a new and different way of looking at Ruby," explains Charles Nutter, JRuby core developer at Sun. "Because it runs on Java applications, it scales very well, tests thoroughly, and allows Ruby to enter enterprises where Ruby and/or Rails have never entered."

"There are now a vast number of Java libraries accessible to Ruby developers," he writes. "JRuby may be a solution for developers who want to scale better or differently. The sandbox security of the JVM* allows developers to build robust Internet-based applications. Giving Ruby developers access to the Java APIs and the community of 6 million developers is a big plus."

JRuby's features include the following:

  • A 1.8.6-compatible Ruby interpreter written in 100% pure Java technology
  • Most built-in Ruby classes
  • Support for interacting with and defining Java classes from within Ruby
  • Support for Bean Scripting Framework (BSF)
  • Distribution under a tri-license: CPL/GPL/LGPL

JRuby on Rails, which is the original Ruby-on-Rails framework running on top of the Java platform, adds to Rails the power and functionality of Java libraries and application servers. Sun is actively working to make Rails applications into Java-platform apps, in the hopes of making JRuby on Rails central to future web development.

jMaki

jMaki jMaki is an Ajax framework that provides a lightweight model for creating JavaScript-centric Ajax-enabled Web 2.0 applications using Java technology, Ruby, PHP, and Phobos. It makes use of CSS layouts, widgets widget model, client services such as publish/subscribe events to tie widgets together, JavaScript action handlers, and a generic proxy to interact with external RESTful web services.

Groovy and Grails

Groovy, a dynamic and agile object-oriented programming language for the Java Platform, can serve both as an alternative to the Java language and a scripting language for the platform, since it has features similar to those of Python, Ruby, Perl, and Smalltalk. A Groovy NetBeans Plugin is available.

Its supporters claim that Groovy:

  • Makes modern programming features available, with an almost zero learning curve, to Java developers.
  • Supports domain-specific languages and other compact syntax so that code becomes easy to read and maintain.
  • Makes writing shell and build scripts easy with its powerful processing primitives, OO abilities, and an Ant DSL.
  • Increases developer productivity by reducing scaffolding code when developing web, GUI, database, or console applications.
  • Simplifies testing by supporting out-of-the-box unit testing and mocking.
  • Seamlessly integrates with all existing Java objects and libraries.
  • Compiles straight to Java bytecode so that it can be used anywhere that the Java platform is used.

Groovy co-founder James Strachan first blogged about Groovy development in August of 2003, after which several versions were released between 2004 and 2006. After the JCP standardization process began, the version numbering was changed and a version called "1.0" was released on Tuesday, January 2, 2007. The release was immediately re-branded as Groovy 1.5 in recognition of its substantial improvements.

Grails is an open-source web application framework that leverages the Groovy language and complements Java web development. Grails, which aims to bring the "coding by convention" paradigm to Groovy, can be used as a standalone development environment (with NetBeans) that hides all configuration details. It was designed to be extensible, easy to learn, and easy to develop on. Grails is targeted both for Java developers looking for an integrated development environment to create web-based applications, and for developers without Java experience looking for a high-productivity environment to build web-based applications.

Grails attempts to provide:

  • Re-use of proven Java technologies such as Hibernate and Spring under a simple, consistent interface.
  • A consistent, easy-to-learn framework.
  • Documentation of the framework most relevant to users.
  • Provide what users expect in areas which are often complex and inconsistent.
  • A powerful and consistent persistence framework.
  • Powerful and easy-to-use view templates using GSP (Groovy Server Pages).
  • Dynamic tag libraries to easily create web page components.
  • Good, easily extended and customized Ajax support.
  • Sample applications which demonstrate the power of the framework.
  • A complete d

Ruby Development Using the NetBeans IDE

 

NetBeans NetBeans IDE offers tools for programming in Ruby, JRuby, jMaki, and the Ruby-on-Rails framework. The NetBeans Ruby support plug-ins provide an IDE for building, running, testing, and debugging Ruby and Ruby-on-Rails applications. Developers can download a Ruby-only version of the NetBeans IDE or add Ruby support to their NetBeans IDE download.
 

The NetBeans Ruby Project Type supports Ruby files, RSpec specification files, and YAML files. Projects can be executed using JRuby or any other native Ruby installation on one's system. The NetBeans IDE has Rake build tool integration and offers access to the Interactive Ruby Shell (IRB).

The Ruby Source Code Editor indents, completes, and highlights Ruby code syntactically as well as semantically, parsing code live as the developer types, so it can match words and brackets, mark errors and occurrences, and display hints and RDoc. Common code snippets can be inserted from live templates with a few keystrokes. Refactoring and support for Test::Unit, Auto Test, and RSpec are well integrated.

NetBeans Ruby-on-Rails Project Type supports Rake targets and database migrations, enabling users to generate Rails projects or generate code through the Rails code generator graphical wizard. The logical project view clearly separates controllers from models, views, and database migrations.

Users can edit RHTML files and deploy projects directly to the integrated WEBrick and Mongrel web servers, jump quickly between a Rails action and its corresponding view, and warp to the browser for the URL most relevant to the file being edited.

The Ruby and Rails Debugger lets developers single-step or run through Ruby code and RHTML files. Users can set breakpoints, look at local variables, navigate the call stack, and switch threads. Hovering the mouse over a variable in the Editor lets developers evaluate the expression and show it in a tooltip.

The NetBeans IDE supports the Fast Debugger extension for Ruby and Rails programs, a pure Ruby debugger, and a JRuby debugger. The Ruby Gems Installation Manager extends Ruby installations using the integrated Ruby Gems packaging system, enabling users to add and manage freely available Ruby software libraries and to distribute their own packages.

Arun Gupta, a technology evangelist for web services and web 2.0 applications at Sun, has explained how to swap the JRuby interpreter in the NetBeans IDE with a C-based Ruby interpreter, and vice versa.

Develop-and-Deploy Scenarios

Ruby has been most often developed on GNU/Linux, and works on many types of UNIX, Mac OS X, Microsoft Windows 95/98/Me/NT/2000/XP, DOS, BeOS, OS/2, and other operating systems. But Sun has now made it very easy to develop Ruby applications on the NetBeans IDE and the Solaris operating system. Here's how.

Deploying on Solaris OS AMP

Solaris Event The Solaris OS AMP stack, also known as Cool Stack, an optimized open-source software stack, provides several packages in the Solaris pkgadd format, enabling developers to install only the ones they need, including CSKruby, which includes Ruby, RubyGems, and Ruby on Rails. The Ruby version is upgraded to 1.8.6 and the Rails version to 1.2.3.

Deploying JRuby on the GlassFish Application Server

Project GlassFish is an open-source community of users, developers, partners, and evangelists who have created an industry-leading Java EE 5 compatible enterprise-quality application server.

JRuby is supported on Project GlassFish V2 through a JRuby on GlassFish module. This module makes it easier to deploy a Ruby-on-Rails application to a GlassFish application server, enabling Rails developers to take advantage of GlassFish.

The JRuby 1.0.1 source bits in this module have been updated with the following Ruby gems:

  • rails-1.2.3
  • rake-0.7.3
  • activesupport-1.4.2
  • activerecord-1.15.3
  • actionpack-1.13.3
  • actionmailer-1.3.3
  • actionwebservice-1.2.3
  • ActiveRecord-JDBC-0.5
Java DB for JRuby Applications

Java DB is Sun's supported distribution of the open-source Apache Derby 100% Java technology database. It is fully transactional, secure, easy to use, standards-based -- SQL, JDBC API, and Java EE -- yet small at only 2 MB. The Apache Derby project has a strong and growing community that includes developers from large companies such as Sun Microsystems and IBM as well as individual contributors. Java DB is also now included in JDK 6.

Why Run Rails on GlassFish?

GlassFish JRuby There are several good reasons to run Rails on the GlassFish application server. First, multithreading: Rails, when run on GlassFish, spins up its extra JRuby servers as needed. Second, GlassFish enables pooling of DB connections, something missing on CRuby Rails. Third, developers can access any Java Naming and Directory Interface (JNDI) API resource from their Rails application, plus any Java Persistence API data source.

Opening the JVM to Other Languages

Opening the JVM to Ruby and the advent of JRuby on Rails marks an advance in Java technology. It enables the faster creation of easily maintained and rich web sites in the Web 2.0 era.

Of particular note is Sun's Da Vinci Machine project, which is extending the JVM with first-class architectural support for languages other than the Java language, with a focus on dynamic languages. The project will prototype a number of extensions to the JVM so that it can run other languages efficiently, with a performance level comparable to that of the Java language itself. Sun is aspiring to a multilanguage renaissance for the JVM architecture.

Ruby's growing popularity, as well as its support on the JVM through JRuby, plus the tooling support of the NetBeans IDE and Solaris OS support in Cool Stack, results in a complete Ruby developer environment, from tools and databases to servers and runtimes.

As other dynamic languages and applications evolve, the flexibility, interoperability, and sheer power of the Java platform should enhance the power of the web for future generations.

_______
* The terms "Java Virtual Machine" and "JVM" = the virtual machine for the Java platform.

For More Information

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.