0

我正在围绕 vlcj 项目构建一个 JRuby 包装器。现在我正在使用 JBundler 来管理依赖项。

Jbundler 给了我一个 .jbundler/classpath.rb 作为:

JBUNDLER_CLASSPATH = []
JBUNDLER_CLASSPATH << '/Users/myth/.m2/repository/uk/co/caprica/vlcj/2.4.1/vlcj-2.4.1.jar'
JBUNDLER_CLASSPATH << '/Users/myth/.m2/repository/net/java/dev/jna/jna/3.5.2/jna-3.5.2.jar'
JBUNDLER_CLASSPATH << '/Users/myth/.m2/repository/net/java/dev/jna/platform/3.5.2/platform-3.5.2.jar'
JBUNDLER_CLASSPATH.freeze
JBUNDLER_CLASSPATH.each { |c| require c }

这是尝试导入 vlcj 的代码:

require 'java'
require '.jbundler/classpath' 

java_import 'com.sun.jna.NativeLibrary'
java_import 'uk.co.caprica.vlcj.runtime.RuntimeUtil'
java_import 'uk.co.caprica.vlcj.binding.LibVlc'

class Player

end

我正在使用 rspec 来驱动我的代码,但是在每次执行时,我总是以:

/Users/myth/.rvm/rubies/jruby-1.7.4/bin/jruby -S rspec spec/bollywood_spec/player_spec.rb
NameError: cannot link Java class uk.co.caprica.vlcj.binding.LibVlc, probable missing dependency: Unable to load library 'vlc': JNA native support (darwin/libvlc.dylib) not found in resource path ()
          for_name at org/jruby/javasupport/JavaClass.java:1242
   get_proxy_class at org/jruby/javasupport/JavaUtilities.java:34
       java_import at file:/Users/myth/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/java/core_ext/object.rb:26
               map at org/jruby/RubyArray.java:2417
       java_import at file:/Users/myth/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/java/core_ext/object.rb:22
            (root) at /Users/myth/Learn/Code/Projects/bollywood/lib/bollywood/player.rb:6
           require at org/jruby/RubyKernel.java:1054
            (root) at /Users/myth/Learn/Code/Projects/bollywood/lib/bollywood.rb:1
           require at org/jruby/RubyKernel.java:1054
            (root) at /Users/myth/Learn/Code/Projects/bollywood/lib/bollywood.rb:2
           require at org/jruby/RubyKernel.java:1054
            (root) at /Users/myth/Learn/Code/Projects/bollywood/spec/spec_helper.rb:1
            (root) at /Users/myth/Learn/Code/Projects/bollywood/spec/spec_helper.rb:2
              load at org/jruby/RubyKernel.java:1073
            (root) at file:/Users/myth/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/kernel19/kernel.rb:1
              each at org/jruby/RubyArray.java:1617
  require_relative at file:/Users/myth/.rvm/rubies/jruby-1.7.4/lib/jruby.jar!/jruby/kernel19/kernel.rb:21
            (root) at /Users/myth/Learn/Code/Projects/bollywood/spec/bollywood_spec/player_spec.rb:1
            (root) at /Users/myth/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:1
   load_spec_files at /Users/myth/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819
rake aborted!
/Users/myth/.rvm/rubies/jruby-1.7.4/bin/jruby -S rspec spec/bollywood_spec/player_spec.rb failed
/Users/myth/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:156:in `run_task'
/Users/myth/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:124:in `initialize'
org/jruby/RubyBasicObject.java:1709:in `__send__'
org/jruby/RubyKernel.java:2213:in `send'
/Users/myth/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:122:in `initialize'
org/jruby/RubyProc.java:255:in `call'
org/jruby/RubyArray.java:1617:in `each'
org/jruby/RubyArray.java:1617:in `each'
org/jruby/RubyKernel.java:1073:in `load'
org/jruby/RubyKernel.java:1093:in `eval'
/Users/myth/.rvm/gems/jruby-1.7.4/bin/ruby_noexec_wrapper:14:in `(root)'

我该如何解决这个问题?

4

1 回答 1

1

我找到了问题的解决方案:

在 MacOSX 上,我需要NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/Applications/VLC .app/Contents/MacOS/lib");在 JNA 的 import 语句之前java_import 'uk.co.caprica.vlcj.binding.LibVlc'找到本地库。

于 2013-07-23T14:10:59.853 回答