please help, understanding RJB valid syntax

Discussion in 'Ruby' started by scootiePuff, Apr 3, 2008.

  1. scootiePuff

    scootiePuff Guest

    i have some basic syntax/format questions for how to begin using RJB
    properly, once successfully installed.

    i've been having a lot of trouble getting the ruby scripts (within a
    rails app) i wrote that make use of rjb to communicate with some 3rd
    party java .jar and .java files to work. i posted some of this at the
    rjb-users forum at rubyforge, and received some answers there, but i
    am still highly confused and would like responses from others who have
    been able to successfully use this tool here.

    ultimate goals:
    load multiple .jar files with rjb, then begin importing 3rd
    party .java classes for use in rails' ruby script(s).


    1. for the default load line from the online docs i've encountered,
    Rjb::load(classpath = '.', jvmargs=[])

    i was told that i can use something like this:
    Rjb::load"#{RAILS_ROOT}/lib/3rdpartystuff/file1.jar"

    now, if i have multiple .jar files that i would like to load, is it
    valid to supply multiple arguments to the above load line in the
    format below? if not, what is the proper way to do this?
    Rjb::load"#{RAILS_ROOT}/lib/3rdpartystuff/file1.jar, #{RAILS_ROOT}/lib/
    3rdpartystuff/lib/file2.jar"

    or do i load each one separately, each on a separate line?
    Rjb::load"#{RAILS_ROOT}/lib/3rdpartystuff/file1.jar"
    Rjb::load"#{RAILS_ROOT}/lib/3rdpartystuff/lib/file2.jar"
    etc.?

    can i alternatively specify,
    Rjb::load(classpath = '#{RAILS_ROOT}/lib/3rdpartystuff/', jvmargs=[])
    or multiple paths in the first argument,
    Rjb::load(classpath = '#{RAILS_ROOT}/lib/3rdpartystuff/, #{RAILS_ROOT}/
    lib/3rdpartystuff/lib', jvmargs=[])
    ?
    (alternatively, without the 'jvmargs' argument.)

    are wildcards ("*") useable in the arguments? eg,
    Rjb::load"#{RAILS_ROOT}/lib/3rdpartystuff/*" (to accommodate ALL
    the .jar files that i'd like loaded in the various children
    subdirectories ?)


    2. from what i understand, the alternative way to load the jvm
    (instead of using Rjb::load), is to use the ENV['CLASSPATH'] approach:
    ENV['CLASSPATH'] = "#{RAILS_ROOT}/lib/3rdpartystuff/
    file1.jar:#{RAILS_ROOT}/lib/3rdpartystuff/lib/file2.jar"
    where each of the paths are separated by a colon (":").
    am i understanding this correctly, so that ENV['CLASSPATH']
    essentially actually alternatively loads the jvm?

    3. how can i tell that the .jar files above have indeed been
    successfully 'loaded'?

    the next step is for me to begin importing the 3rd party .java classes
    in order to instantiate objects and start using their methods.

    i do something like this,
    test_import = Rjb::import('com.3rdpartyco.3rdpartyproduct.services.
    3rdpartysvcname.SomeSvcClass')

    the problem is that i keep encountering the error message,
    Exception in thread "main" java.lang.NoClassDefFoundError: com.
    3rdpartyco.3rdpartyproduct.services.3rdpartysvcname.SomeSvcClass

    so i'm not so sure that the .jar files have been successfully loaded,
    or how to otherwise direct rjb to find the java classes' files ?


    please advise. how would you approach the above problems?
     
    scootiePuff, Apr 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. buddy249
    Replies:
    1
    Views:
    588
    debayan_p
    Jun 23, 2009
  2. John Goche

    please help understanding syntax

    John Goche, Jan 7, 2012, in forum: Java
    Replies:
    5
    Views:
    355
    Roedy Green
    Jan 16, 2012
  3. Zach Dennis

    RJB 0.1.6 on 1.8.2

    Zach Dennis, Nov 18, 2004, in forum: Ruby
    Replies:
    1
    Views:
    97
    Zach Dennis
    Nov 18, 2004
  4. Adam Keys

    rjb and Java 1.5

    Adam Keys, Mar 10, 2006, in forum: Ruby
    Replies:
    0
    Views:
    120
    Adam Keys
    Mar 10, 2006
  5. Tim Swetonic

    RubyJavaBridge (rjb)

    Tim Swetonic, Jul 24, 2006, in forum: Ruby
    Replies:
    0
    Views:
    87
    Tim Swetonic
    Jul 24, 2006
Loading...

Share This Page