call jar file from ruby class

杀马特。学长 韩版系。学妹 提交于 2020-01-15 16:43:35

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/15174068/call-jar-file-from-ruby-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!