1

如何jar从类中调用文件(java 归档文件)ruby。并从中访问函数/方法。

我指的是以下链接

但我收到以下错误:

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

我该如何解决这个问题。

4

2 回答 2

3

您可以使用系统调用。如果您有很多用户,您可能会遇到性能问题,但对于大多数人来说,这应该可行:

# 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
于 2013-06-09T23:38:27.087 回答
1

您不能从 Ruby 调用 Java 代码。您可能想看看JRuby。JRuby 是您链接中的人使用的,您可以在他jruby Main.rb在控制台中键入时看到它。

于 2013-03-02T11:59:30.727 回答