-4

爪哇:

import java.util.*;
import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.

JRuby:

java_import org.scribe.builder.*;
java_import org.scribe.builder.api.*;
java_import org.scribe.model.*;
java_import org.scribe.oauth.*;

收到此错误 JRuby :

wrong constant name OrgScribeBuilder*
4

2 回答 2

1

您需要使用include_packagehttps ://github.com/jruby/jruby/wiki/JRuby-Reference#importing-a-package-into-a-class-or-module

于 2013-05-01T11:16:32.177 回答
0

你应该得到错误NameError: cannot load Java class org.scribe.builder.。Java 类必须以其完整的限定名导入。

require 'java'
require 'scribe-1.3.4.jar'
# you can't use the start import -> java_import 'org.scribe.builder.*'
java_import 'org.scribe.builder.ServiceBuilder'
service = ServiceBuilder.new;

或如@Idan 所写,使用 include_package

require 'java'
require 'scribe-1.3.4.jar'

# use include_package to have an analogue way like in Java -> 'import org.scribe.builder.*'
module Demo
  include_package 'org.scribe.builder'
  service = ServiceBuilder.new;
end

欢呼弗兰克

于 2013-05-10T06:56:03.877 回答