1 | object = Classname.new_with_sig('signature', parameter[,more parameters]) |
1 | tararchive_instance.extractContents(file_instance) |
1 | tararchive_instance._invoke('extractContents', 'Ljava.io.File;', file_instance) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # Include 'rjb' library into your application require 'rjb' # Load the JVM specifying the jar files to include and any other optional JVM arguments Rjb::load(classpath = '.:/path/to/tar.jar', jvmargs=[]) # Import the classes you want to use into a Ruby variable # specify the full package path to the classes. tararchive = Rjb::import('com.ice.tar.TarArchive') fileinputstream = Rjb::import('java.io.FileInputStream') file = Rjb::import('java.io.File') # Create objects of the classes. Use the new method directly or use # the 'new_with_sig' call to invoke overloaded constructors with arguments # Directory you want to extract the files in this case, the current directory file_instance = file.new_with_sig('Ljava.lang.String;','.') # inputstream instance of the file to extract fileinputstream_instance = fileinputstream.new_with_sig('Ljava.lang.String;','test.tar') # tararchive instance of the file to be extracted. tararchive_instance = tararchive.new_with_sig('Ljava.io.InputStream;'\ ,fileinputstream_instance) # Invoke the method from the class and capture the results. # Use either the direct call of the method, # or the '_invoke' call to invoke overloaded methods. p 'Extracting file.....' tararchive_instance.extractContents(file_instance) p 'Done...' |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |