Class: BindIt::JarLoader
- Inherits:
-
Object
- Object
- BindIt::JarLoader
- Defined in:
- lib/bind-it/jar_loader.rb
Class Attribute Summary collapse
-
.jvm_args ⇒ Object
An array of flags to pass to the JVM machine.
-
.log_file ⇒ Object
A log file to send JVM output to.
Class Method Summary collapse
-
.init_rjb ⇒ Object
Load Rjb and create Java VM.
-
.load(jar, path) ⇒ Object
Load a JAR through Jruby/Rjb.
-
.load_jar_jruby(jar, path) ⇒ Object
Load a Jruby jar.
-
.load_jar_rjb(jar, path) ⇒ Object
Laad an Rjb jar.
-
.set_java_logging ⇒ Object
Redirect the output of the JVM to log.
Class Attribute Details
.jvm_args ⇒ Object
An array of flags to pass to the JVM machine.
8 9 10 |
# File 'lib/bind-it/jar_loader.rb', line 8 def jvm_args @jvm_args end |
.log_file ⇒ Object
A log file to send JVM output to.
10 11 12 |
# File 'lib/bind-it/jar_loader.rb', line 10 def log_file @log_file end |
Class Method Details
.init_rjb ⇒ Object
Load Rjb and create Java VM.
44 45 46 47 |
# File 'lib/bind-it/jar_loader.rb', line 44 def self.init_rjb ::Rjb::load(nil, self.jvm_args) set_java_logging if self.log_file end |
.load(jar, path) ⇒ Object
Load a JAR through Jruby/Rjb.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bind-it/jar_loader.rb', line 18 def self.load(jar, path) if !::File.readable?(path + jar) raise "Could not find JAR file " + "(looking in #{path}#{jar})." end if RUBY_PLATFORM =~ /java/ set_java_logging if self.log_file load_jar_jruby(jar,path) else load_jar_rjb(jar,path) end end |
.load_jar_jruby(jar, path) ⇒ Object
Load a Jruby jar.
32 33 34 |
# File 'lib/bind-it/jar_loader.rb', line 32 def self.load_jar_jruby(jar, path) require path + jar end |
.load_jar_rjb(jar, path) ⇒ Object
Laad an Rjb jar.
37 38 39 40 41 |
# File 'lib/bind-it/jar_loader.rb', line 37 def self.load_jar_rjb(jar,path) self.init_rjb unless ::Rjb::loaded? jar = path + jar ::Rjb::add_jar(jar) end |
.set_java_logging ⇒ Object
Redirect the output of the JVM to log.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bind-it/jar_loader.rb', line 50 def self.set_java_logging system, print_stream, file = nil, nil, nil if RUBY_PLATFORM =~ /java/ system = java.lang.System print_stream = java.io.PrintStream file = java.io.File else system = Rjb::import('java.lang.System') print_stream = Rjb::import('java.io.PrintStream') file = Rjb::import('java.io.File') end ps = print_stream.new(file.new(self.log_file)) ps.write(::Time.now.strftime("[%m/%d/%Y at %I:%M%p]\n\n")) system.setOut(ps) system.setErr(ps) end |