尝试使用Ruby Java Bridge(RJB)gem时出错“无法创建Java VM” [英] Error “can't create Java VM” trying to use Ruby Java Bridge (RJB) gem
问题描述
我正在尝试实现Ruby Java Bridge(RJB)gem以与JVM通信,以便我可以运行Open-NLP gem。我已经在Windows 8上安装并运行了Java。至少我所知道的所有迹象都表明Java已经安装并且可以运行。但是,使用RJB的尝试失败并显示消息无法创建Java VM。 (在其他情况下,我有时会得到未定义的方法`dlopen for Fiddle:Module,这也是难以理解的。)
I'm trying to implement the Ruby Java Bridge (RJB) gem to talk to JVM so that I can run the 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. But, attempts to use RJB fail with the message "can't create Java VM". (I do sometimes get "undefined method `dlopen' for Fiddle:Module" in other cases, which is also indecipherable.)
我最初只是默认安装了JDK。由于我的64位系统,这安装了64位Java。我不确定Ruby和RJB是否会与此对话,所以我安装了32位JRE。但是,错误是相同的。
I initially just installed JDK per defaults. Due to my 64-bit system, this installed 64-bit Java. I wasn't sure whether or not Ruby and RJB would talk to this, so I installed the 32-bit JRE. However, the error is the same.
我是否可以运行以确保JVM在Ruby之外工作?
Is there any further test I can run to ensure that JVM is working outside of Ruby?
有人能告诉我运行Windows / Ruby / RJB / JVM需要做些什么吗?
Can someone tell me what I might need to do to run Windows/Ruby/RJB/JVM?
谢谢...
我使用BitNami Rubystack和Ruby 1.9.3p448运行Windows 8。
I am running Windows 8 with BitNami Rubystack and Ruby 1.9.3p448.
根据testjava.jsp,Java似乎可用:
Java seems to be available according to testjava.jsp:
这是代码,包括我找到的网址:
This is the code, including the URL where I found it:
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
以下是错误消息:
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>'
我找不到任何其他信息为什么它无法创建Java VM。如果我能获得更多信息,那将会非常有帮助。我会很感激这些信息或修复此问题。谢谢...
I cannot find any additional information as to why it "can't create 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...
编辑添加有关RJB OPEN-NLP要求的信息......
EDIT TO ADD INFORMATION REGARDING OPEN-NLP REQUIREMENT FOR RJB...
这是我试图运行的代码,取自Github / Open-nlp:
This is the code I am trying to run, taken from 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
此时在代码中:
=begin
Examples
Simple tokenizer
=end
OpenNLP.load
调用链是dl .rb,fiddle.rb和jar_loader.rb。 jarloader.rb起始行43:
The call chain is to dl.rb, fiddle.rb and jar_loader.rb. jarloader.rb starting line 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
此时,我得到了创建JVM的相同错误。所以,我还是试图运行RJB。错误链如下:
At this point, I get the same error creating JVM. So, I reverted to attempting to run 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)>'
推荐答案
首先,我需要卸载Java x64并安装JDK x586以获得32位支持。
First, I needed to uninstall Java x64 and install JDK x586 for 32-bit support.
然后,设置 JAVA_HOME
如下:
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_40
并添加 JAVA_HOME
到我的路径:
%JAVA_HOME%\bin;C:\Program Files (x86)\Java\jre7\bin;
这解决了无法创建Java VM问题。
This resolved the "can't create Java VM' problem.
设置 $ DEBUG = false
,或者注释掉该行,消除了所有其他消息。 $ DEBUG
mode显示可能被捕获并解决的错误消息,以便可以忽略它们。
Setting $DEBUG=false
, or commenting out the line, eliminated all other messages. $DEBUG
mode displays error messages that may be caught and resolved so they can be ignored.
无法创建Java VM问题解决后,所有其他错误消息属于这种类型,因此是假的。
After the "can't create Java VM" problem was resolved, all other error messages were of this type and therefore were spurious.
JetBrains对Rubymine的支持为我解决了这个问题。他们非常好,尤其是Serge,我推荐他们的产品因为他们的支持。
JetBrains support for Rubymine solved this problem for me. They are very good, especially Serge, and I recommend their products because of their support.
这篇关于尝试使用Ruby Java Bridge(RJB)gem时出错“无法创建Java VM”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!