3

I have a rails app. I also wrote a method in Java which constructs a 4 dimensional tree structure. Its for querying my database. The code is relatively complex that i dont want to rewrite it in Ruby again. Is there any way I can use this Java method that I wrote in my rails app.

This would be for a Heroku hosted app.

If so how should I go about learning about how to make this happen? What keywords should I google? Can anyone point me to known good resources ...

Appreciate it.

1
  • You could have a look at RJB (the Ruby Java Bridge). Commented May 1, 2012 at 1:38

1 Answer 1

5

You can expose the Java method to a Ruby client by talking over the network. There are lots of great abstraction layers for exposing Java code via a server.

One such abstraction layer is Thrift. You could use Thrift's code generation engine to create a client library for the Ruby side and an interface for your Java server. You can run the Java RPC server anywhere and make calls to it from your Ruby client within your Rails app on Heroku.

Or, if that's too heavy-weight for what you're doing, you could also just shell out to your Java program and have it send the results of the method invocation to STDOUT. In Ruby, you can shell out with backticks (ie `java MyProgram`).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.