0

I'm using warbler to build a jar out of ruby classes so that it can be run as a interactive application. Now, I want to use that jar as a library in my java application. I've noticed that warbler generated jar contains ruby classes compiled using jrubyc without --javac option. So dows anyone know how to generate a jar using warbler so that it can be run as a standalone application as well can be used as a library in Java projects so that object of ruby classes can be created in Java?

Below is how my ruby code is structured:

core
    |--- lib
        |----a.rb
        |----b.rb
    |---java_lib

a.rb contents:

require 'b'
class A
    def test
        ob=b.new
        puts ob.test
    end
end

b.rb contents:

class B
    def test
        puts "test"
    end
end

Then, I've created a jar of above using warbler, put a jar in classpath of another java project and tries to access a.test. But it says "unable to load -- b"

Keyur Shah
  • 81
  • 1
  • 6
  • "Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist)" – the Tin Man Dec 29 '13 at 04:43
  • Currently I'm not able to use ruby classes from a jar in java. I'm finding out a way to call them. And for that I believe that my compiled ruby classes should be java compatible which is possible with "jrubyc" with "--javac" as a option. but I don't know how to pass those options in warbler so that final jar can be run as a standalone as well as can be used as a library in java application. Please let me know if you need a warbler config or any specific thing. Currently I don't have any implementation as I'm in a process of finding out how to make it work. – Keyur Shah Dec 29 '13 at 05:42
  • From the help for jrubyc: `--javac Generate and compile .java classes to accompany the script`. From a quick test, this option creates both a `.class` and a `.java` file. Do you need the `.java` file for some reason? Can you amend your question to include exactly what is missing that you need? – Shepmaster Dec 30 '13 at 17:30
  • @shepmaster Okay. Below is how my ruby code is structured: `core |--- lib |---java_lib |----a.rb |----b.rb |----bin` a.rb contents: `require 'b' class A def test ob=b.new puts ob.test end end` b.rb contents: `class B def test puts "test" end end` Then, I've created a jar of above using warbler, put a jar in classpath of another java project and tries to access a.test. But it says "unable to load -- b" – Keyur Shah Dec 31 '13 at 01:13
  • Your last comment seems to be the same as your [other question](http://stackoverflow.com/questions/20819258/org-jruby-embed-evalfailedexception-loaderror-no-such-file-to-load), which I've answered there. Can you explain why you need to pass the `--javac` option? Also, your last comment would be better as an edit to your question, as the formatting is not ideal. – Shepmaster Dec 31 '13 at 03:23
  • @Shepmaster: Edited original question. I want to pass --javac option so that generated ruby class have method signatures specified using java_signature. And thus it will help me to create a ruby class object in java as well as invoke method on them. – Keyur Shah Dec 31 '13 at 04:49

1 Answers1

0

Warbler does not currently allow you to pass that option. I see that you have already opened an issue about this. Beyond that, your best bet would be to try hacking the line of code that invokes jrubyc to add the option and see how things fail.

I don't run the Warbler project, but it's my opinion that this is not the point of Warbler, so you may just want to write a Rakefile (or Makefile, or POM, or whatever) that runs jrubyc and creates the JAR for you.

In addition, your updates to the question focus on the unable to load -- b problem, which is completely unrelated to the original question, and I believe I have answered that in your other question.

Community
  • 1
  • 1
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • I've extracted the ruby jar on runtime in my java application and then configure load paths for ScriptingContainer. This has resolve the issue related to "Unable to load". But there is new issue now. Ruby code uses native libraries using JNA. So I normally provides path of native libraries using -J-cp option on command line. So is there any option in JRuby api which will allow me to do the same thing which -J-cp option does on command line. LoadPaths are equivalent to -I option in JRuby. – Keyur Shah Dec 31 '13 at 18:25