简体   繁体   English

jruby 不理解 import 语句

[英]jruby does not understand import statement

I'm converting a project written with JRuby 1.7 in mind to JRuby 9.4.我正在将一个使用 JRuby 1.7 编写的项目转换为 JRuby 9.4。 One of the files starts like this:其中一个文件是这样开头的:

if RUBY_PLATFORM == 'java'

  require 'java'
  import java.lang.management.ManagementFactory

  ....

end

The import does not work anymore. import不再起作用。 With JRuby 9.4, just compiling this file produces the error message NoMethodError: undefined method `import' for main:Object .使用 JRuby 9.4,仅编译此文件会产生错误消息NoMethodError: undefined method `import' for main:Object

My understanding was that require 'java' would provide the import method, and at least it was working with JRuby 1.7.我的理解是require 'java'会提供import方法,至少它可以与 JRuby 1.7 一起使用。

In case it matters: We are using the imported class like this:以防万一:我们像这样使用导入的 class:

current_heap_in_bytes = ManagementFactory.getMemoryMXBean.getHeapMemoryUsage.used

On this page:在此页:

https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-class-files https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-class-files

There is mention of the java_import method.提到了java_import方法。 Does that help?这有帮助吗?

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

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