我正在尝试实现Ruby Java Bridge(RJB)gem以与JVM对话,以便我可以运行Open-NLP gem。我在Windows 8上安装并运行了Java。至少我所知道的所有迹象都表明Java已经安装并且可以正常运行。但是,使用RJB的尝试失败并显示消息“无法创建Java VM”。 (在其他情况下,我有时会为“小提琴:模块”获得“未定义的方法`dlopen”,这也是难以辨认的。)
我最初只是默认安装了JDK。由于我的64位系统,这安装了64位Java。我不确定Ruby和RJB是否会与之对话,所以我安装了32位JRE。但是,错误是一样的。
我是否可以运行以确保JVM在Ruby之外工作?
有人可以告诉我运行Windows / Ruby / RJB / JVM可能需要做些什么吗?
谢谢...
我使用BitNami Rubystack和Ruby 1.9.3p448运行Windows 8。
根据testjava.jsp,Java似乎可用:
这是代码,包括我找到它的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
以下是错误消息:
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”的原因的其他信息。如果我能获得更多信息,那将会非常有用。我会很感激这些信息或修复此问题。谢谢......
编辑增加关于RJB的开放 - 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
代码中的这一点:
=begin
Examples
Simple tokenizer
=end
OpenNLP.load
调用链是dl.rb,fiddle.rb和jar_loader.rb。 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
此时,我在创建JVM时遇到了同样的错误。所以,我还是试图运行RJB。错误链如下:
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)>'
答案 0 :(得分:6)
首先,我需要卸载Java x64并安装JDK x586以获得32位支持。
然后,按如下方式设置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”的问题。
设置$DEBUG=false
或注释掉该行,消除了所有其他消息。 $DEBUG
模式显示可能被捕获和解决的错误消息,以便可以忽略它们。
解决了“无法创建Java VM”问题后,所有其他错误消息都属于这种类型,因此是虚假的。
JetBrains对Rubymine的支持为我解决了这个问题。他们非常好,特别是Serge,我推荐他们的产品是因为他们的支持。