我在Windows XP机器上安装了JRuby 1.6.0。我还下载了Google gdata库。这段代码:
require "java"
$CLASSPATH << "D:\\javalib\\gdata\\java\\lib\\*"
include_class "com.google.gdata.client.docs"
给出了这个错误:
org/jruby/javasupport/JavaClass.java:1052:in `for_name': cannot load Java class
com.google.gdata.client.docs (NameError)
from org/jruby/javasupport/JavaUtilities.java:34:in `get_proxy_class'
from C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/shared/builtin/javasupport/co
re_ext/object.rb:46:in `java_import'
from C:/jruby-1.6.0.RC1/lib/ruby/site_ruby/shared/builtin/javasupport/co
re_ext/object.rb:26:in `include_class'
from download_gdocs.rb:5:in `(root)'
Google gdata Java库位于D:\javalib\gdata\java\lib
。例如,如果我输入jar tvf D:\javalib\gdata\java\lib\gdata-client-1.0.jar
,我会得到(部分)这个:
0 Fri Feb 04 15:25:54 PST 2011 com/google/gdata/data/docs/
904 Fri Feb 04 15:25:54 PST 2011 com/google/gdata/client/docs/DocsService$Versions.class
6686 Fri Feb 04 15:25:54 PST 2011 com/google/gdata/client/docs/DocsService.class
答案 0 :(得分:3)
$CLASSPATH
不支持glob表达式。相反,require
每个.jar单独:
Dir["D:\\javalib\\gdata\\java\\lib\\*.jar"].each { |jar| require jar }