0

I have a piece of Ruby code which depends on a binary built from C. I generally call the binary through backticks. But now when I package the Ruby code into a jar using Warbler, I'm not sure on how I'd be able to access the binary.

My code structure looks like this:

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 

I used warble to build this entire structure into a jar. In Ruby, I can access my a.out through the following statement in exec.rb.

exec = "#{File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'ext'))}/a.out}"; 
`exec`

But when I try this code packaged as a jar I get the following error:

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

So, how do I access the executable packaged in a jar.

arrac
  • 597
  • 1
  • 5
  • 15

1 Answers1

0

Put the jar in the lib folder.

Require it in the code

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

Then it should be available to be used.

Edit:

Maybe this is what you are looking for https://stackoverflow.com/a/600198/643500 you can implement it with JRuby.

Community
  • 1
  • 1
Sully
  • 14,672
  • 5
  • 54
  • 79
  • I had tried something similar, but it didn't work. I think my question was ambiguous so I've rephrased my question with more background to what I've done. – arrac Jan 18 '13 at 06:49
  • Thanks for the link. I'll try to give it a shot. – arrac Jan 18 '13 at 17:44