JRuby Cookbook

Book description

If you're interested in JRuby, you probably don't need a tutorial on Ruby, Rails, or Java -- you just need to know how to get things done. This Cookbook offers practical solutions for using the Java implementation of the Ruby language, with targeted recipes for deploying Rails web applications on Java servers, integrating JRuby code with Java technologies, developing JRuby desktop applications with Java toolkits, and more. Using numerous reusable code samples, JRuby Cookbook shows you how to:

  • Install and update JRuby on Windows, Mac OS X, and Linux, and IDEs such as NetBeans and Eclipse
  • Package and deploy Rails apps on Java Servlet containers and Java EE application servers, including JBoss, Tomcat, and GlassFish
  • Integrate Ruby and Rails applications with popular Java EE technologies such as JMS, JMX, JPA, Spring, and Hibernate
  • Develop desktop and client applications with cross-platform Java UI technologies and toolkits such as Swing, SWT, and Java 2D
  • Maximize the flexibility of your testing and build environment, using both existing Java-based tools such as Ant and Maven and newer Ruby-based tools such as Rake, Raven, and Buildr

The JRuby interpreter combines Ruby's simplicity and ease of use with Java's extensive libraries and technologies, a potent blend that opens new possibilities for Ruby, Rails, and Java. This Cookbook helps you take full advantage of JRuby's potential.

"The JRuby Cookbook is an excellent book for any polyglot who is trying to bridge the gap between Java and Ruby. It provides solutions to specific problems developers face in both their development and testing environments, along with the applications they're building."-- Bob McWhirter, Research & Prototyping, Red Hat Middleware

Publisher resources

View/Submit Errata

Table of contents

  1. JRuby Cookbook
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. Preface
    1. Audience
    2. Organization
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. Comments and Questions
    7. Acknowledgments
      1. Justin Edelson
      2. Henry Liu
  4. 1. Getting Started
    1. Introduction
      1. Ruby
      2. JRuby
    2. Installing JRuby
      1. Problem
      2. Solution
      3. Discussion
        1. Windows
        2. Linux and Mac OS X
      4. See Also
    3. Managing Packages with RubyGems
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Using Both Ruby and JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Sharing RubyGems
      1. Problem
      2. Solution
      3. Discussion
    6. Referencing Java Classes from Ruby
      1. Problem
      2. Solution
      3. Discussion
    7. Converting a Ruby Array into a Java Array
      1. Problem
      2. Solution
      3. Discussion
    8. Adding JAR Files to the Classpath
      1. Problem
      2. Solution
      3. Discussion
    9. Extending a Java Class in Ruby
      1. Problem
      2. Solution
      3. Discussion
    10. Implementing a Java Interface in Ruby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Opening Java Classes with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Setting Up Eclipse for JRuby Development
      1. Problem
      2. Solution
      3. Discussion
        1. RDT
        2. DLTK
        3. Running JRuby as a Java application
      4. See Also
    13. Setting Up NetBeans for JRuby Development
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Platform Detection in a JRuby Application
      1. Problem
      2. Solution
      3. Discussion
  5. 2. JRuby on Rails
    1. Introduction
    2. Installing and Setting Up Rails
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Packaging Rails As a Java EE Web Application
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Using an External Gem Repository with a Web Application
      1. Problem
      2. Solution
      3. See Also
    5. Configuring the JRuby-Rack Servlet
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Packaging Rails with a JNDI DataSource
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Deploying Rails on Tomcat
      1. Problem
      2. Solution
        1. Windows
        2. Linux and OS X
      3. Discussion
      4. See Also
    8. Deploying Rails on JBoss
      1. Problem
      2. Solution
        1. Windows
        2. Linux and OS X
      3. Discussion
      4. See Also
    9. Deploying Rails on Jetty
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Deploying Rails with jetty_rails
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Deploying Rails with Mongrel
      1. Problem
      2. Solution
      3. Discussion
    12. Deploying Rails on the GlassFish v2 Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Using the GlassFish v3 Gem
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Using ActiveRecord Outside of Rails
      1. Problem
      2. Solution
      3. Discussion
    15. Accessing Common Java Servlet Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. Configuring Session Storage
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. Controlling the Classes, Directories, and Other Files Packaged into a Rails WAR File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. Changing the Name of the WAR File and the Staging Area
      1. Problem
      2. Solution
      3. See Also
    19. Deploying a Rails Application to the Root Context
      1. Problem
      2. Solution
      3. Discussion
        1. Tomcat
        2. JBoss
        3. Jetty
      4. See Also
    20. Creating a Rails Application with Aptana Studio
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    21. Accessing Static Files in Your Rails Java EE Application
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  6. 3. Java Integration
    1. Introduction
    2. Executing Ruby from Java
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Invoking JRuby Through the Bean Scripting Framework
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Invoking JRuby Through Java Scripting Support
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Logging from Ruby with Jakarta Commons Logging
      1. Problem
      2. Solution
      3. Discussion
    6. Using the Java Concurrency Utilities
      1. Problem
      2. Solution
      3. Discussion
    7. Creating JavaBean Style Accessor Methods
      1. Problem
      2. Solution
      3. Discussion
    8. Writing Consistent Code
      1. Problem
      2. Solution
      3. Discussion
    9. Transforming XML with TrAX
      1. Problem
      2. Solution
      3. Discussion
    10. Creating a Pool of JRuby Runtimes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Performing Remote Management with JMX
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Accessing Native Libraries with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  7. 4. Enterprise Java
    1. Introduction
    2. Creating a JNDI Context
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Sending JMS Messages
      1. Problem
      2. Solution
      3. Discussion
    4. Receiving JMS Messages
      1. Problem
      2. Solution
      3. Discussion
    5. Implementing an Enterprise JavaBean with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Defining Spring Beans in JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Creating Refreshable JRuby Spring Beans
      1. Problem
      2. Solution
      3. Discussion
    8. Defining JRuby Spring Beans Inline
      1. Problem
      2. Solution
    9. Applying Spring-Aware Interfaces to JRuby Objects
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Creating Spring MVC Controllers with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Using Hibernate with JRuby
      1. Problem
      2. Solution
      3. Discussion
    12. Using the Java Persistence API with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Making SOAP Calls
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Simplifying LDAP Access
      1. Problem
      2. Solution
      3. Discussion
  8. 5. User Interface and Graphics
    1. Introduction
    2. Creating Swing Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Swing Event Handling
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Long-Running Tasks in Swing Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Packaging Standalone Applications
      1. Problem
      2. Solution
        1. Executable JAR
        2. Windows executable
        3. Mac OS X application
      3. Discussion
      4. See Also
    6. Packaging JRuby Web Start Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Creating JRuby Applets
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Manipulating Images
      1. Problem
      2. Solution
        1. RMagick4J
        2. ImageVoodoo
      3. Discussion
      4. See Also
    9. Creating SWT Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. Accessing the Native Desktop
      1. Problem
      2. Solution
    11. Accessing the System Tray
      1. Problem
      2. Solution
        1. Swing
        2. SWT
      3. See Also
    12. Swing Development with JRuby Domain-Specific Languages
      1. Problem
      2. Solution
        1. Swiby
        2. Cheri::Swing
        3. Profligacy
      3. See Also
    13. Using the Monkeybars Framework for Swing Development
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Creating Qt Applications with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  9. 6. Build Tools
    1. Introduction
    2. Adding Ruby Scripting to Ant Builds
      1. Problem
      2. Solution
      3. Discussion
    3. Using Ruby in Ant Conditions
      1. Problem
      2. Solution
      3. Discussion
    4. Writing an Ant Task in Ruby
      1. Problem
      2. Solution
    5. Adding Ruby Scripting to Maven Builds
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. Writing a Maven Plugin with JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Building Java Projects with Raven
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. Referencing Libraries with Raven
      1. Problem
      2. Solution
      3. Discussion
    9. Hosting a Private Raven Repository
      1. Problem
      2. Solution
      3. Discussion
    10. Running JUnit Tests with Raven
      1. Problem
      2. Solution
      3. See Also
    11. Building Java Projects with Buildr
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Referencing Libraries with Buildr
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. Building with Rake Inside Hudson
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. Adding Ruby Script to a Hudson Job
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  10. 7. Testing
    1. Introduction
    2. Unit Testing Java Code with Test/Unit
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Unit Testing Java Code with dust
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Unit Testing Java Code with Expectations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. Testing Java Code with RSpec
      1. Problem
      2. Solution
        1. Spec framework
        2. Story framework
      3. Discussion
      4. See Also
    6. Creating Mock Objects with Mocha
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. Modifying the JtestR Classpath
      1. Problem
      2. Solution
      3. Discussion
    8. Grouping Tests for JtestR
      1. Problem
      2. Solution
      3. Discussion
    9. Using the JtestR Command-Line Options
      1. Problem
      2. Solution
      3. See Also
    10. Running JtestR with Ant
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. Running JtestR with Maven
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. Improving JtestR Performance
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  11. 8. The JRuby Community
    1. Introduction
    2. Building JRuby from Source
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. Submitting an Issue Report for JRuby
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. Using the JRuby Mailing Lists
      1. Problem
      2. Solution
      3. Discussion
  12. Index
  13. About the Authors
  14. Colophon
  15. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  16. Copyright

Product information

  • Title: JRuby Cookbook
  • Author(s): Justin Edelson, Henry Liu
  • Release date: November 2008
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596554118