Integrating a ruby environment into a Java maven project is quite easy. I recently built BlenderCss, a java project that needed to use the Compass gem. To solution was to utilize the gem via jruby.

You will need..

1. Dependencies Section in pom.xml
...
<!-- The Jruby Dependency -->
<dependency>
    <groupId>org.jruby</groupId>
    <artifactId>jruby</artifactId>
    <version>1.7.12</version>
</dependency>
...

2. The ruby class you plan to use.

class MyApi

end

JRubyRunner.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import org.jruby.Ruby;
import org.jruby.javasupport.JavaEmbedUtils;

import java.util.ArrayList;
import java.util.List;

public class JRubyRunner {
    public static void main(String[] args) {
        List paths = new ArrayList();
        paths.add("classpath:gems/compass-0.12.2/lib");
        Ruby ruby = JavaEmbedUtils.initialize(paths);
        ruby.getLoadService().require("compass");  // require "compass"
        ruby.evalScriptlet("Compass::Exec::SubCommandUI.perform! :compile"); // perform a compile command.
    }
}

Note: jRuby is slow to initialize, so use it wisely.