Class: NativeLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby_art/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.



12
13
14
15
# File 'lib/jruby_art/native_loader.rb', line 12

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.



4
5
6
# File 'lib/jruby_art/native_loader.rb', line 4

def current_path
  @current_path
end

#separatorObject (readonly)

Returns the value of attribute separator.



4
5
6
# File 'lib/jruby_art/native_loader.rb', line 4

def separator
  @separator
end

Instance Method Details

#add_native_path(pth) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/jruby_art/native_loader.rb', line 17

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