1

How to call jar file (a java archive file) from ruby class. And access the functions/methods from it.

I am refering the following link

But I am getting the following error:

'require': cannot load such file -- /tmp/Test.jar (LoadError)

How can I resolve this issue.

user1881251
  • 83
  • 1
  • 4
  • 11

2 Answers2

3

You can use a system call. You may have performance issues if you have lots of users, but for most this should work:

# Create a directory (in this sample called "jars") inside public directory and move your jar file inside the newly created directory.

def externaljar

 argsA = ""
 argsB = ""

    Dir.chdir("#{RAILS_ROOT}/public/jars/") do

        # Use your path to the java according to the java directory installed in your machine.

        retResult  = system("/home/user/java/jdk1.7.0/bin/java -jar JSpell.jar #{argsA} #{argsB}")

    end #chdir
 end
John Moore
  • 178
  • 2
  • 6
1

You can't call Java code from Ruby. You might want to have a look at JRuby. JRuby is what the guy from your link uses, you can see it when he types jruby Main.rb in the console.

enthrops
  • 729
  • 5
  • 14