Class: NativeLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/propane/native_loader.rb

Overview

This class knows how to dynamically set the 'java' native library path It might not work with java 9?

Defined Under Namespace

Modules: JC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNativeLoader

Returns a new instance of NativeLoader.



15
16
17
18
# File 'lib/propane/native_loader.rb', line 15

def initialize
  @separator = JC::File.pathSeparatorChar
  @current_path = JC::System.getProperty('java.library.path')
end

Instance Attribute Details

#current_pathObject (readonly)

Returns the value of attribute current_path.



6
7
8
# File 'lib/propane/native_loader.rb', line 6

def current_path
  @current_path
end

#separatorObject (readonly)

Returns the value of attribute separator.



6
7
8
# File 'lib/propane/native_loader.rb', line 6

def separator
  @separator
end

Instance Method Details

#add_native_path(pth) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/propane/native_loader.rb', line 20

def add_native_path(pth)
  current_path << separator << pth
  JC::System.setProperty('java.library.path', current_path)
  field = JC::Class.for_name('java.lang.ClassLoader')
                   .get_declared_field('sys_paths')
  return unless field

  field.accessible = true # some jruby magic
  field.set(JC::Class.for_name('java.lang.System').get_class_loader, nil)
end