Reputation: 93
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
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