user1881251
user1881251

Reputation: 93

call jar file from ruby class

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.

Upvotes: 1

Views: 4351

Answers (2)

John Moore
John Moore

Reputation: 178

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

Upvotes: 3

enthrops
enthrops

Reputation: 729

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.

Upvotes: 1

Related Questions