why so many different ways to include Java classes into JRuby? What are the differences? Which one should I use?
Asked
Active
Viewed 1.4k times
2 Answers
23
You can find quite a few examples about working with Java classes at:
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
It states, that you should use java_import
instead of import
due to the JRUBY-3171 bug.
Also include_class
is or will be deprecated (JRUBY-3797) in favor of java_import
.
Currently java_import
is the recommended way to import a Java class.

rubiii
- 6,903
- 2
- 38
- 51
-
3FYI: the up-to-date URL to follow is: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby – inger Dec 15 '11 at 13:54
-
What about `java_require` ? – detj Mar 24 '17 at 14:25
13
import
doesn't play well with Rake, so it's discouraged. java_import
is the newest, and recommended. include_class
has been deprecated. Apart from that they all do the same thing, and are actually aliases of each other.
import
is an alias for java_import
and java_import
calls include_class
.

Theo
- 131,503
- 21
- 160
- 205
-
1If I read this answer yesterday, I'd wouldn't have wasted a day today! – Paul Biggar Nov 14 '11 at 03:42