JRuby supports -I for Ruby code, naturally, but also understands Java’s -cp / -classpath option for Java classes:
命令行:
-I
ruby -I/path/to/library my_program.rb
-J-cp
jruby -J-cp /path/to/library.jar
环境变量:
JRuby supports RUBYOPT for finding Ruby code, and the Java equivalent ( CLASSPATH ) for finding Java classes
Ruby全局变量:
As an alternative or a supplement to the command-line classpath, you
can add a . jar or directory to the $CLASSPATH variable inside Ruby itself
(much as you’re used to doing with $LOAD_PATH or $: for Ruby libraries):
$CLASSPATH << '/usr/local/lib/jemmy/jemmy.jar'
require '/usr/local/lib/jemmy/jemmy.jar'
Both the -I argument and the $LOAD_PATH vari-able work on both Ruby and Java libraries in JRuby:
204-08-17 12:00 : 第60 页
204-08-17 16:12 : 第98 页
文章
找类 classpath
JRuby supports -I for Ruby code, naturally, but also understands Java’s -cp / -classpath option for Java classes:
命令行:
-I
-J-cp
环境变量:
JRuby supports RUBYOPT for finding Ruby code, and the Java equivalent ( CLASSPATH ) for finding Java classes
Ruby全局变量:
As an alternative or a supplement to the command-line classpath, you can add a . jar or directory to the $CLASSPATH variable inside Ruby itself (much as you’re used to doing with $LOAD_PATH or $: for Ruby libraries):
Both the -I argument and the $LOAD_PATH vari-able work on both Ruby and Java libraries in JRuby:
加载类
Ruby code will see Java packages as Ruby modules
The most reliable way to refer to a Java class in JRuby is by tacking Java:: onto the beginning of the full package name
default package:
JRuby provides top-level functions like com , org , java , and javax .
导入类(By Importing)
A common con-vention is to define a new constant consisting of just the class name
Ruby provides a handy java_import shortcut that does exactly this kind of assignment
使用对象
Static Methods
Static Fields
treat the field like a Ruby class-level method, calling it with dot notation and a Ruby-style snake_case name
对象构造(Object Construction)