From: scootiePuff Date: 2008-04-04T03:45:09+09:00 Subject: please help, understanding RJB valid syntax 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?