Skip to Main Content
JRuby Cookbook
book

JRuby Cookbook

by Justin Edelson, Henry Liu
November 2008
Intermediate to advanced content levelIntermediate to advanced
224 pages
5h 2m
English
O'Reilly Media, Inc.
Content preview from JRuby Cookbook

Chapter 3. Java Integration

Introduction

The first two chapters examined JRuby almost entirely from a Ruby-centric perspective. In the next few chapters, we look at leveraging JRuby more as a toolkit for Ruby and Java integration. There are two primary integration approaches that we will explore in this chapter. The first is how JRuby can be used to add functionality to a Java application; the second is how Ruby programs can take advantage of the wide array of preexisting Java libraries. Frequently, these types of integration are combined. For example, when mixing Java and Ruby code, using a consistent configuration for application logging can be useful, something which is explored in Logging from Ruby with Jakarta Commons Logging.

There are three primary APIs for embedding Ruby into a Java application:

  • The JRuby low-level API

  • The Bean Scripting Framework (BSF)

  • Java Scripting, defined by JSR 223

These APIs are the subject of the first three recipes in this chapter. The differences between the low-level API and either BSF or Java Scripting are fairly obvious—the low-level API ties your Java code directly to JRuby, whereas both BSF and Java Scripting are abstractions of the JRuby runtime and, in fact, support multiple scripting languages. In general, you will use the JRuby API when you need tight control over the runtime’s configuration. The choice between BSF and Java Scripting is largely based on deployment environment—BSF support is more consistent on Java 5, whereas Java Scripting is ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby Cookbook, 2nd Edition

Ruby Cookbook, 2nd Edition

Lucas Carlson, Leonard Richardson
Groovy 2 Cookbook

Groovy 2 Cookbook

Andrey Adamovich, Luciano Fiandesio
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao
Ruby Phrasebook

Ruby Phrasebook

Jason Clinton

Publisher Resources

ISBN: 9780596155063Errata Page