javarubyclasspathrjb

rjb: Calling java methods from Ruby with compiled files in several directories


I have a Java library compiled in two directories:

Directory A
   com.foo.bar.app.* //without test
Directory B
   com.foo.bar.app.test.*

My objective, it is to call some simple java methods of com.foo.bar.app.test (with dependencies in the directory A) using the rjb gem.

In the examples, they instance with this:

Rjb::load(classpath = '.', jvmargs=[])

How can i use the rjb to call a method methodFromCreate() from a class com.foo.bar.app.test.create?


Solution

  • You could use something like:

    require 'rjb'
    
    RJB_LOAD_PATH = ["Directory A", "Directory B"].join(File::PATH_SEPARATOR)
    RJB_OPTIONS = ['-Djava.awt.headless=true','-Xms16m', '-Xmx32m']
    
    Rjb::load RJB_LOAD_PATH, RJB_OPTIONS
    
    my_create_class = Rjb::import('com.foo.bar.app.test.Create')
    my_create = my_create_class.new
    
    my_create.methodFromCreate()
    

    I added de RJB_OPTIONS we are using at the moment just for exemplification, if you need any awt stuff remove dthe -Djava.awt,... option.