This is probably really simple, but all my Google results came back with JRuby, which isn't what I want to know. I'm curious if a regular Ruby app (e.g. a Rails app or a Sinatra app) could somehow be made to reference and call a Java library that's in the classpath? Ideally one that works on Heroku.
4 Answers
Not directly. Java libraries run within the JVM, Ruby apps in their own VM. If you want those two to communicate, you will need to create some kind of a comms channel between them (there are various solutions, see f.e. http://code.google.com/p/activemessaging/).
1 Comment
Paul
Thanks, activemessaging was what I was looking for.
I succeeded calling my Java program like this from Rails controller:
system "java -cp postgresql-9.0-801.jdbc4.jar:./ Main"
Couple of things to note:
- I've compiled my Main class and put it in root of my rails app (and git-pushed it to heroku).
- This call blocks rails app until java program finishes execution
- It would probably work better with delayed_job gem (I'm working on it now)
Comments
- http://rjb.rubyforge.org/
- another option would be if the jar is executable and do something like execute system command and run it in a 'session'/terminal