JRuby + Neo4J Problems

I have JRuby on Rails app, which is using an ueber JAR to access Neo4J. The Neo4J database is in the rails root directory unter “data/”. By starting the HTTP Server I got today this Exception:

IllegalArgumentException: No index provider 'lucene' found. Maybe the intended provider (or one more of its dependencies) aren't on the classpath or it failed to load.

The problem was in the “data/”. In some way it was corrupt. I am not sure. After I exchanged the “data/” directory with an older version, the HTTP Server started without any problems.

Mizuno

Mizuno is Webserver for JRuby on Rails.

I looked for different options to run my JRuby App. After some googleing I found Mizumo. It was very easy to install:

jruby -S gem install mizuno

and very easy to start. Just go into the root directory of your rails app and exec.

mizuno

or if you want to start on Port 80.

sudo mizuno --port 80

Mizuno is the fastest option for Reck applications on JRuby:

Mizuno: 6106.66 req/s (mean) 
Jetty (via jruby-rack): 2011.67 req/s (mean) 
Mongrel: 1479.15 req/sec (mean)

Using Java in Rails with JRuby

JRuby is a pretty good Java implementation of Ruby. One of the biggest advantages of JRuby is that you can use Java Classes in your Ruby on Rails App. You can import JARs and take advantages of all the Java Libraries and Frameworks. In that way you don’t have to throw away your old Java Code. You can build a JAR and use it inside your new fancy Ruby App.

I recommend to build a Uber JAR, which contains all dependencies of your Java App. That is more easy to handle. You have to put your Uber JAR into the “lib” directory of your rails app. Than you have to import the JAR in the “application.rb”.

require "lib/your-java-all.jar"

That’s it! Know you can access the Classes inside the JAR. If you want to use a Java Class in a Controller you have to include the class:

include_class Java::org.trophic.graph.service.LocationServiceImpl
include_class Java::org.trophic.graph.factory.LocationFactory

And here is how you can use the Java Classes:

locationService = LocationFactory.locationService
locations = locationService.locations

And here is the full example of the controller:

class PageController < ApplicationController

  include_class Java::org.trophic.graph.service.LocationServiceImpl
  include_class Java::org.trophic.graph.factory.LocationFactory

  def home
      locationService = LocationFactory.locationService
      @locations = locationService.locations
  end

end

It is super easy! Isn’t it?

JRuby

I am familiar with Ruby on Rails. I think that is the best Framework for Web Development. Yesterday I installed JRuby. That is the Ruby language implemented in Java. It is pretty good. Here is the Homepage:

http://www.jruby.org

On the Download Page there is a bundle for Mac OS X, too.

http://www.jruby.org/download

The installation worked pretty smooth. After the installation you can use in the command line like that:

jruby -S --version

You can install the rails framework like that.

jruby -S gem install rails

and create a new project like that

jruby -S rails new blog

It works pretty good. And with JRuby you can directly access Java classes. You can import JAR files and take advantage of the whole Java world.

JRuby + Spring + AspectJ + Neo4J

I am playing around with JRuby and Neo4j as Graph Engine. My set up on the backend side contains a Java Application with Spring Annotations, AspectJ and Neo4J. In the frontend I have a Rails App with JRuby.

Any time I try to access a class that have an annotation like “@NodeEntity”, I get an Exception. It seems that Spring and AspectJ is to much in this chain. I should get rid of Spring and AspectJ.