Sha256: b401260bd806c85721ed0d901c364d073a755f6cc7fe0893afd8f0047cd17a67

Contents?: true

Size: 894 Bytes

Versions: 22

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

# 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

  # This module wraps java_import with namespace JC
  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

22 entries across 22 versions & 2 rubygems

Version Path
propane-4.0.0-java lib/propane/native_loader.rb
picrate-2.5.2-java lib/picrate/native_loader.rb
picrate-2.5.1-java lib/picrate/native_loader.rb
propane-3.11.0-java lib/propane/native_loader.rb
picrate-2.5.0-java lib/picrate/native_loader.rb
picrate-2.4.2-java lib/picrate/native_loader.rb
picrate-2.4.1-java lib/picrate/native_loader.rb
picrate-2.4.0-java lib/picrate/native_loader.rb
propane-3.10.0-java lib/propane/native_loader.rb
propane-3.9.0-java lib/propane/native_loader.rb
picrate-2.3.0-java lib/picrate/native_loader.rb
propane-3.8.0-java lib/propane/native_loader.rb
propane-3.7.1-java lib/propane/native_loader.rb
propane-3.7.0.pre-java lib/propane/native_loader.rb
picrate-2.2.0-java lib/picrate/native_loader.rb
propane-3.6.0-java lib/propane/native_loader.rb
picrate-2.1.2-java lib/picrate/native_loader.rb
picrate-2.1.1-java lib/picrate/native_loader.rb
picrate-2.1.0-java lib/picrate/native_loader.rb
picrate-2.0.1-java lib/picrate/native_loader.rb