O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JRuby Cookbook

Book Description

If you're interested in JRuby, you probably don't need a turorialon Ruby, Rails, or Java -- you just need to know how to get thingsdone. This Cookbook offers practical solutions for using the Javaimplementation of the Ruby language, with targeted recipes fordeploying Rails web applications on Java servers, integrating JRubycode with Java technologies, developing JRuby desktop applicationswith 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, andIDEs such as NetBeans and Eclipse

  • Package and deploy Rails apps on Java Servlet containers andJava EE application servers, including JBoss, Tomcat, andGlassFish

  • Integrate Ruby and Rails applications with popular Java EEtechnologies such as JMS, JMX, JPA, Spring, and Hibernate

  • Develop desktop and client applications with cross-platformJava UI technologies and toolkits such as Swing, SWT, and Java2D

  • Maximize the flexibility of your testing and build environment,using both existing Java-based tools such as Ant and Maven andnewer Ruby-based tools such as Rake, Raven, and Buildr

  • The JRuby interpreter combines Ruby's simplicity and ease of usewith Java's extensive libraries and technologies, a potent blendthat opens new possibilities for Ruby, Rails, and Java. ThisCookbook helps you take full advantage of JRuby's potential."The JRuby Cookbook is an excellent book for any polyglotwho is trying to bridge the gap between Java and Ruby. It providessolutions to specific problems developers face in both theirdevelopment and testing environments, along with the applicationsthey're building." -- Bob McWhirter, Research & Prototyping,Red Hat Middleware

    Table of Contents

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