简体   繁体   English

尝试使用Ruby Java Bridge(RJB)gem时出错“无法创建Java VM”

[英]Error “can't create Java VM” trying to use Ruby Java Bridge (RJB) gem

I'm trying to implement the Ruby Java Bridge (RJB) gem to talk to JVM so that I can run the Open-NLP gem. 我正在尝试实现Ruby Java Bridge(RJB)gem以与JVM通信,以便我可以运行Open-NLP gem。 I have Java installed and running on Windows 8. All indications, at least those I know of, are that Java is installed and operational. 我在Windows 8上安装并运行了Java。至少我所知道的所有迹象都表明Java已经安装并且可以正常运行。 But, attempts to use RJB fail with the message "can't create Java VM". 但是,使用RJB的尝试失败并显示消息“无法创建Java VM”。 (I do sometimes get "undefined method `dlopen' for Fiddle:Module" in other cases, which is also indecipherable.) (在其他情况下,我有时会为“小提琴:模块”获得“未定义的方法`dlopen”,这也是难以辨认的。)

I initially just installed JDK per defaults. 我最初只是默认安装JDK。 Due to my 64-bit system, this installed 64-bit Java. 由于我的64位系统,这安装​​了64位Java。 I wasn't sure whether or not Ruby and RJB would talk to this, so I installed the 32-bit JRE. 我不确定Ruby和RJB是否会与之对话,所以我安装了32位JRE。 However, the error is the same. 但是,错误是一样的。

Is there any further test I can run to ensure that JVM is working outside of Ruby? 是否有任何进一步的测试可以确保JVM在Ruby之外工作?

Can someone tell me what I might need to do to run Windows/Ruby/RJB/JVM? 有人能告诉我运行Windows / Ruby / RJB / JVM可能需要做些什么吗?

Thanks... 谢谢...

I am running Windows 8 with BitNami Rubystack and Ruby 1.9.3p448. 我使用BitNami Rubystack和Ruby 1.9.3p448运行Windows 8。

Java seems to be available according to testjava.jsp: 根据testjava.jsp,Java似乎可用: 在此输入图像描述

This is the code, including the URL where I found it: 这是代码,包括我找到它的URL:

class FiddleTry

# http://devjete.wordpress.com/2011/01/31/installing-rjb-1-3-4-on-windows-7-32bit-wo-vc/
  require 'rjb'
  out = Rjb::import('java.lang.System').out  <== Line 5 is here
  out.print('Hello Rjb from ')
  p out._classname
end

Here are the error messages: 以下是错误消息:

C:/Users/Richard/RubymineProjects/Utilities/fiddle_try.rb:5:in `import': can't create Java VM (RuntimeError)
    from C:/Users/Richard/RubymineProjects/Utilities/fiddle_try.rb:5:in `<class:FiddleTry>'
    from C:/Users/Richard/RubymineProjects/Utilities/fiddle_try.rb:1:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

I cannot find any additional information as to why it "can't create Java VM". 我找不到任何关于为什么它“无法创建Java VM”的其他信息。 It would really help if additional information was available to me. 如果我能获得更多信息,那将会非常有用。 I would appreciate either that information or a fix for this. 我会很感激这些信息或修复此问题。 Thanks... 谢谢...

EDIT TO ADD INFORMATION REGARDING OPEN-NLP REQUIREMENT FOR RJB... 编辑添加有关RJB的开放式NLP要求的信息......

This is the code I am trying to run, taken from Github/Open-nlp: 这是我试图运行的代码,取自Github / Open-nlp:

class OpenNlpSample
  ENV['JAVA_HOME'] = "C:/Program Files/Java/jdk1.7.0_25" if ENV['JAVA_HOME'].nil?
  ENV['LD_LIBRARY_PATH'] = "C:/Program Files/Java/jdk1.7.0_25/bin; C:/Program Files (x86)/Java/jre7" if ENV['LD_LIBRARY_PATH'].nil?
  # Load the module
  require 'open-nlp'
  gem_bin = File.join(Gem.loaded_specs['open-nlp'].full_gem_path, 'bin/')
# Set an alternative path to look for the JAR files.
# Default is gem's bin folder.
# OpenNLP.jar_path = '/path_to_jars/'
# OpenNLP.jar_path = File.expand_path('../../ruby/lib/ruby/gems/1.9.1/gems/open-nlp-0.1.4/bin',__FILE__)
  OpenNLP.jar_path = gem_bin
# Set an alternative path to look for the model files.
# Default is gem's bin folder.
# OpenNLP.model_path = '/path_to_models/'
  OpenNLP.model_path = gem_bin
# Pass some alternative arguments to the Java VM.
# Default is ['-Xms512M', '-Xmx1024M'].
# OpenNLP.jvm_args = ['-option1', '-option2']
  OpenNLP.jvm_args = ['-Xms512M', '-Xmx1024M']
# Redirect VM output to log.txt
  OpenNLP.log_file = 'log.txt'
# Set default models for a language.
# OpenNLP.use :language
  OpenNLP.use :english

=begin
  Examples

  Simple tokenizer
=end

  OpenNLP.load

  sent = "The death of the poet was kept from his poems."
  tokenizer = OpenNLP::SimpleTokenizer.new

  tokens = tokenizer.tokenize(sent).to_a
# => %w[The death of the poet was kept from his poems .]


  #Maximum entropy tokenizer, chunker and POS tagger

  OpenNLP.load

  chunker   = OpenNLP::ChunkerME.new
  tokenizer = OpenNLP::TokenizerME.new
  tagger    = OpenNLP::POSTaggerME.new

  sent   = "The death of the poet was kept from his poems."

  tokens = tokenizer.tokenize(sent).to_a
# => %w[The death of the poet was kept from his poems .]

  tags   = tagger.tag(tokens).to_a
# => %w[DT NN IN DT NN VBD VBN IN PRP$ NNS .]

  chunks = chunker.chunk(tokens, tags).to_a
# => %w[B-NP I-NP B-PP B-NP I-NP B-VP I-VP B-PP B-NP I-NP O]


  #Abstract Bottom-Up Parser

  OpenNLP.load

  sent      = "The death of the poet was kept from his poems."
  parser = OpenNLP::Parser.new
  parse = parser.parse(sent)

  parse.get_text.should eql sent

  parse.get_span.get_start.should eql 0
  parse.get_span.get_end.should eql 46
  parse.get_child_count.should eql 1

  child = parse.get_children[0]

  child.text # => "The death of the poet was kept from his poems."
  child.get_child_count # => 3
  child.get_head_index #=> 5
  child.get_type # => "S"


  #Maximum Entropy Name Finder*

                           OpenNLP.load

  text = File.read('./spec/sample.txt').gsub!("\n", "")

  tokenizer   = OpenNLP::TokenizerME.new
  segmenter   = OpenNLP::SentenceDetectorME.new
  ner_models  = ['person', 'time', 'money']

  ner_finders = ner_models.map do |model|
    OpenNLP::NameFinderME.new("en-ner-#{model}.bin")
  end

  sentences = segmenter.sent_detect(text)
  named_entities = []

  sentences.each do |sentence|

    tokens = tokenizer.tokenize(sentence)

    ner_models.each_with_index do |model,i|
      finder = ner_finders[i]
      name_spans = finder.find(tokens)
      name_spans.each do |name_span|
        start = name_span.get_start
        stop  = name_span.get_end-1
        slice = tokens[start..stop].to_a
        named_entities << [slice, model]
      end
    end

  end


=begin
  Loading specific models

  Just pass the name of the model file to the constructor. The gem will search for the file in the OpenNLP.model_path folder.
=end

                                                                                                                          OpenNLP.load

  tokenizer = OpenNLP::TokenizerME.new('en-token.bin')
  tagger = OpenNLP::POSTaggerME.new('en-pos-perceptron.bin')
  name_finder = OpenNLP::NameFinderME.new('en-ner-person.bin')
# etc.


  #Loading specific classes

  #You may want to load specific classes from the OpenNLP library that are not loaded by default. The gem provides an API to do this:

# Default base class is opennlp.tools.
      OpenNLP.load_class('SomeClassName')
# => OpenNLP::SomeClassName

# Here, we specify another base class.
  OpenNLP.load_class('SomeOtherClass', 'opennlp.tools.namefind')
# => OpenNLP::SomeOtherClass



  end

At this point in the code: 在代码中的这一点:

=begin
  Examples

  Simple tokenizer
=end

  OpenNLP.load

The call chain is to dl.rb, fiddle.rb and jar_loader.rb. 调用链是dl.rb,fiddle.rb和jar_loader.rb。 jarloader.rb starting line 43: jarloader.rb起始行43:

# Load Rjb and create Java VM.
def self.init_rjb
  ::Rjb::load(nil, self.jvm_args)
  set_java_logging if self.log_file
end

At this point, I get the same error creating JVM. 此时,我得到了创建JVM的相同错误。 So, I reverted to attempting to run RJB. 所以,我还是试图运行RJB。 The error chain is as follows: 错误链如下:

Fast Debugger (ruby-debug-ide 0.4.17, ruby-debug-base19x 0.11.30.pre12) listens on 127.0.0.1:59488
Uncaught exception: can't create Java VM
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/jar_loader.rb:45:in `load'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/jar_loader.rb:45:in `init_rjb'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/jar_loader.rb:38:in `load_jar_rjb'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/jar_loader.rb:27:in `load'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/binding.rb:63:in `load_jar'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/binding.rb:71:in `block in load_default_jars'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/binding.rb:68:in `each'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/binding.rb:68:in `load_default_jars'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/bind-it-0.2.7/lib/bind-it/binding.rb:55:in `bind'
    D:/BitNami/rubystack-1.9.3-12/ruby/lib/ruby/gems/1.9.1/gems/open-nlp-0.1.4/lib/open-nlp.rb:14:in `load'
    C:/Users/Richard/RubymineProjects/Utilities/open_nlp_sample.rb:32:in `<class:OpenNlpSample>'
    C:/Users/Richard/RubymineProjects/Utilities/open_nlp_sample.rb:1:in `<top (required)>'

First, I needed to uninstall Java x64 and install JDK x586 for 32-bit support. 首先,我需要卸载Java x64并安装JDK x586以获得32位支持。

Then, set JAVA_HOME as follows: 然后,按如下方式设置JAVA_HOME

JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_40

and add JAVA_HOME to my path: 并将JAVA_HOME添加到我的路径:

%JAVA_HOME%\bin;C:\Program Files (x86)\Java\jre7\bin;

This resolved the "can't create Java VM' problem. 这解决了“无法创建Java VM”的问题。

Setting $DEBUG=false , or commenting out the line, eliminated all other messages. 设置$DEBUG=false或注释掉行,消除了所有其他消息。 $DEBUG mode displays error messages that may be caught and resolved so they can be ignored. $DEBUG模式显示可能被捕获和解决的错误消息,以便可以忽略它们。

After the "can't create Java VM" problem was resolved, all other error messages were of this type and therefore were spurious. 在“无法创建Java VM”问题得到解决之后,所有其他错误消息都属于这种类型,因此是虚假的。

JetBrains support for Rubymine solved this problem for me. JetBrains对Rubymine的支持为我解决了这个问题。 They are very good, especially Serge, and I recommend their products because of their support. 他们非常好,特别是Serge,我推荐他们的产品,因为他们的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM