使Imports在OSX上与vlcj和JRuby一起使用

时间:2013-07-23 03:13:48

标签: classpath jruby vlcj

我正在围绕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)'

如何解决问题?

1 个答案:

答案 0 :(得分:1)

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

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