2013-07-23 71 views
0

我正在圍繞vlcj項目構建JRuby包裝。現在我正在使用JBundler來管理依賴關係。在OSX上使用vlcj和JRuby導入

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

我找到了解決問題的辦法:

MacOSX上我需要NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"/Applications/VLC .app/Contents/MacOS/lib");是import語句java_import 'uk.co.caprica.vlcj.binding.LibVlc'爲JNA找到本機庫前。