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.
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`).