Sha256: eab3aacb1425c5eca556f2090c70f4cd5576e3ef97ff062be1b14553e1597b28

Contents?: true

Size: 810 Bytes

Versions: 24

Compression:

Stored size: 810 Bytes

Contents

# This class knows how to dynamically set the 'java' native library path
# It might not work with java 9?
class NativeLoader
  attr_reader :separator, :current_path

  module JC
    java_import 'java.lang.Class'
    java_import 'java.lang.System'
    java_import 'java.io.File'
  end

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

  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
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
jruby_art-2.2.2 lib/jruby_art/native_loader.rb
jruby_art-2.2.1 lib/jruby_art/native_loader.rb
jruby_art-2.2.0 lib/jruby_art/native_loader.rb
jruby_art-1.7.0 lib/jruby_art/native_loader.rb
jruby_art-2.1.0.pre lib/jruby_art/native_loader.rb
jruby_art-2.0.0.pre lib/jruby_art/native_loader.rb
jruby_art-1.6.4 lib/jruby_art/native_loader.rb
jruby_art-1.6.3 lib/jruby_art/native_loader.rb
jruby_art-1.6.2 lib/jruby_art/native_loader.rb
jruby_art-1.6.1 lib/jruby_art/native_loader.rb
jruby_art-1.6.0 lib/jruby_art/native_loader.rb
jruby_art-1.5.2 lib/jruby_art/native_loader.rb
jruby_art-1.5.1 lib/jruby_art/native_loader.rb
jruby_art-1.5.0 lib/jruby_art/native_loader.rb
jruby_art-1.4.9 lib/jruby_art/native_loader.rb
jruby_art-1.4.8 lib/jruby_art/native_loader.rb
jruby_art-1.4.7 lib/jruby_art/native_loader.rb
jruby_art-1.4.6 lib/jruby_art/native_loader.rb
jruby_art-1.4.5 lib/jruby_art/native_loader.rb
jruby_art-1.4.4 lib/jruby_art/native_loader.rb