5

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 4

6

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

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

1 Comment

Thanks, activemessaging was what I was looking for.
4

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

1
  1. http://rjb.rubyforge.org/
  2. another option would be if the jar is executable and do something like execute system command and run it in a 'session'/terminal

Comments

0

You can perform the block of commands inline of ruby (jruby) file:

importString = <<-eos
  java -version
  ls -l
eos

exec importString

This OK for Mac, but Windows jruby has some limitations.

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.