0

私は、C から構築されたバイナリに依存する Ruby コードを持っています。通常、バックティックを使用してバイナリを呼び出します。しかし、今では 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 ではa.out、exec.rb の次のステートメントを介してmy にアクセスできます。

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 にパッケージ化された実行可能ファイルにアクセスするにはどうすればよいでしょうか。

4

1 に答える 1

0

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

その後、使用できるようになるはずです。

編集:

多分これはあなたが探しているものですhttps://stackoverflow.com/a/600198/643500 JRubyで実装できます。

于 2013-01-17T16:53:51.257 に答える