Synopses & Reviews
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
Offers step-by-step solutions on how to deploy Rails applications on Java application platforms and integrate them with Java frameworks. As a Java implementation of the Ruby language, JRuby lets developers build Ruby-on-Rails web applications that can take advantage of Java libraries and servers, or be integrated with other Java applications. But there are plenty of tricky details along the way, and this concise Cookbook helps developers solve specific JRuby programming problems with targeted recipes.
In Using JRuby you'll venture into the wide world of open-source Ruby and Java libraries. Write Ruby on Rails web applications that run on Java servers like Tomcat. Use Java's JDBC or Hibernate to easily connect Ruby to industry-standard databases. Test your Java program using Ruby's elegant Cucumber and RSpec frameworks. Create dazzling desktop user interfaces with frameworks like Limelight and Monkeybars. Package a Rails or plain Ruby project for easy deployment to any Java environment.
JRuby lets you merge the best of several possible worlds, so you can create unique software using the best tools available. This book is your definitive guide.
About the Author
Charles O Nutter is the principal developer of JRuby. He has worked at Ventera, Sun, and now, EngineYard. During his time on the project, he has steered JRuby to its place as the fastest Ruby implementation.
Thomas Enebo has striven since 2003 to make JRuby a piece of software that will capture the hearts and minds of Ruby and Java developers everywhere. He works at EngineYard alongside Charles and Nick.
Nick Sieger is a prolific blogger and programmer who contributes not only to the JRuby core, but also to numerous libraries that Ruby programmers depend on every day in their work with JRuby. He works at EngineYard.
Ola Bini writes software at Thoughtworks Studios, and is the author of Practical JRuby on Rails. He is constantly pushing the boundaries between programming languages.
Ian Dees is the author of Scripted GUI Testing With Ruby. By day, he slings C++, Ruby, LabVIEW, and other languages for a test equipment manufacturer in Portland, Oregon.
Table of Contents
Preface; Audience; Organization; Conventions Used in This Book; Using Code Examples; Safari® Books Online; Comments and Questions; Acknowledgments; Chapter 1: Getting Started; 1.1 Introduction; 1.2 Installing JRuby; 1.3 Managing Packages with RubyGems; 1.4 Using Both Ruby and JRuby; 1.5 Sharing RubyGems; 1.6 Referencing Java Classes from Ruby; 1.7 Converting a Ruby Array into a Java Array; 1.8 Adding JAR Files to the Classpath; 1.9 Extending a Java Class in Ruby; 1.10 Implementing a Java Interface in Ruby; 1.11 Opening Java Classes with JRuby; 1.12 Setting Up Eclipse for JRuby Development; 1.13 Setting Up NetBeans for JRuby Development; 1.14 Platform Detection in a JRuby Application; Chapter 2: JRuby on Rails; 2.1 Introduction; 2.2 Installing and Setting Up Rails; 2.3 Packaging Rails As a Java EE Web Application; 2.4 Using an External Gem Repository with a Web Application; 2.5 Configuring the JRuby-Rack Servlet; 2.6 Packaging Rails with a JNDI DataSource; 2.7 Deploying Rails on Tomcat; 2.8 Deploying Rails on JBoss; 2.9 Deploying Rails on Jetty; 2.10 Deploying Rails with jetty_rails; 2.11 Deploying Rails with Mongrel; 2.12 Deploying Rails on the GlassFish v2 Server; 2.13 Using the GlassFish v3 Gem; 2.14 Using ActiveRecord Outside of Rails; 2.15 Accessing Common Java Servlet Information; 2.16 Configuring Session Storage; 2.17 Controlling the Classes, Directories, and Other Files Packaged into a Rails WAR File; 2.18 Changing the Name of the WAR File and the Staging Area; 2.19 Deploying a Rails Application to the Root Context; 2.20 Creating a Rails Application with Aptana Studio; 2.21 Accessing Static Files in Your Rails Java EE Application; Chapter 3: Java Integration; 3.1 Introduction; 3.2 Executing Ruby from Java; 3.3 Invoking JRuby Through the Bean Scripting Framework; 3.4 Invoking JRuby Through Java Scripting Support; 3.5 Logging from Ruby with Jakarta Commons Logging; 3.6 Using the Java Concurrency Utilities; 3.7 Creating JavaBean Style Accessor Methods; 3.8 Writing Consistent Code; 3.9 Transforming XML with TrAX; 3.10 Creating a Pool of JRuby Runtimes; 3.11 Performing Remote Management with JMX; 3.12 Accessing Native Libraries with JRuby; Chapter 4: Enterprise Java; 4.1 Introduction; 4.2 Creating a JNDI Context; 4.3 Sending JMS Messages; 4.4 Receiving JMS Messages; 4.5 Implementing an Enterprise JavaBean with JRuby; 4.6 Defining Spring Beans in JRuby; 4.7 Creating Refreshable JRuby Spring Beans; 4.8 Defining JRuby Spring Beans Inline; 4.9 Applying Spring-Aware Interfaces to JRuby Objects; 4.10 Creating Spring MVC Controllers with JRuby; 4.11 Using Hibernate with JRuby; 4.12 Using the Java Persistence API with JRuby; 4.13 Making SOAP Calls; 4.14 Simplifying LDAP Access; Chapter 5: User Interface and Graphics; 5.1 Introduction; 5.2 Creating Swing Applications; 5.3 Swing Event Handling; 5.4 Long-Running Tasks in Swing Applications; 5.5 Packaging Standalone Applications; 5.6 Packaging JRuby Web Start Applications; 5.7 Creating JRuby Applets; 5.8 Manipulating Images; 5.9 Creating SWT Applications; 5.10 Accessing the Native Desktop; 5.11 Accessing the System Tray; 5.12 Swing Development with JRuby Domain-Specific Languages; 5.13 Using the Monkeybars Framework for Swing Development; 5.14 Creating Qt Applications with JRuby; Chapter 6: Build Tools; 6.1 Introduction; 6.2 Adding Ruby Scripting to Ant Builds; 6.3 Using Ruby in Ant Conditions; 6.4 Writing an Ant Task in Ruby; 6.5 Adding Ruby Scripting to Maven Builds; 6.6 Writing a Maven Plugin with JRuby; 6.7 Building Java Projects with Raven; 6.8 Referencing Libraries with Raven; 6.9 Hosting a Private Raven Repository; 6.10 Running JUnit Tests with Raven; 6.11 Building Java Projects with Buildr; 6.12 Referencing Libraries with Buildr; 6.13 Building with Rake Inside Hudson; 6.14 Adding Ruby Script to a Hudson Job; Chapter 7: Testing; 7.1 Introduction; 7.2 Unit Testing Java Code with Test/Unit; 7.3 Unit Testing Java Code with dust; 7.4 Unit Testing Java Code with Expectations; 7.5 Testing Java Code with RSpec; 7.6 Creating Mock Objects with Mocha; 7.7 Modifying the JtestR Classpath; 7.8 Grouping Tests for JtestR; 7.9 Using the JtestR Command-Line Options; 7.10 Running JtestR with Ant; 7.11 Running JtestR with Maven; 7.12 Improving JtestR Performance; Chapter 8: The JRuby Community; 8.1 Introduction; 8.2 Building JRuby from Source; 8.3 Submitting an Issue Report for JRuby; 8.4 Using the JRuby Mailing Lists; Colophon;