Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Warbler中,如何通过Ruby代码访问已编译的二进制文件?_Ruby_Jar_Jruby_Warbler - Fatal编程技术网

在Warbler中,如何通过Ruby代码访问已编译的二进制文件?

在Warbler中,如何通过Ruby代码访问已编译的二进制文件?,ruby,jar,jruby,warbler,Ruby,Jar,Jruby,Warbler,我有一段Ruby代码,它依赖于从C构建的二进制文件。我通常通过backticks调用二进制文件。但是现在,当我使用Warbler将Ruby代码打包到一个jar中时,我不确定如何访问二进制文件 我的代码结构如下所示: root/ |--bin/ |--exec.rb #This is the executable when I call java -jar example.jar |--lib/ |--Module1.rb #This dir conta

我有一段Ruby代码,它依赖于从C构建的二进制文件。我通常通过backticks调用二进制文件。但是现在,当我使用Warbler将Ruby代码打包到一个jar中时,我不确定如何访问二进制文件

我的代码结构如下所示:

root/  
  |--bin/
       |--exec.rb   #This is the executable when I call java -jar example.jar
  |--lib/
       |--Module1.rb #This dir contains all the ruby modules my code requires
  |--ext/
       |--a.out     #A binary compiled with gcc
  |--.gemspec       #A file to guide warbler into building this structure into a jar 
我使用
warble
将整个结构构建到一个jar中。在Ruby中,我可以通过exec.rb中的以下语句访问我的
a.out

exec = "#{File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'ext'))}/a.out}"; 
`exec`
但是,当我尝试将此代码打包为jar时,会出现以下错误:

/bin/sh: file:/path/to/my/jar/example.jar!/root/ext/a.out: not found

那么,如何访问打包在jar中的可执行文件。

jar
放在
lib
文件夹中

在代码中需要它

require 'java'
Dir["#{File.expand_path(File.join(Rails.root, 'lib'))}/\*.jar"].each { |jar| require jar } 
# A war is treated as a directory.  If that is not successful add the lib folder to the CLASSPATH environment variable
那么它应该是可用的

编辑:


也许这就是你想要的,你可以用JRuby来实现它。

我也尝试过类似的方法,但没有成功。我认为我的问题模棱两可,所以我用更多的背景来重新表述我的问题。谢谢链接。我试着试一试。