Thursday, April 02, 2020

JRuby include_package Gotcha and Workaround

JRuby is such a great version of Ruby for a Java developer since it provides all the power of Java libraries with all the expressiveness of Ruby syntax.

Still, while developing Glimmer, I ran into this gotcha. Apparently, if you include Java packages (e.g. java.util.*) via include_package (or import, which uses include_package behind the scenes), it only brings the package to the exact class you're in, without trickling down into subclasses/submodules and nested-classes/nested-modules.

This new gem should work around this by enhancing "include_package" to include a Java package across nested classes/modules and subclasses/submodules.

https://rubygems.org/gems/nested_inherited_jruby_include_package

Examples

The nested_inherited_jruby_include_package gem's instructions and gotchas are on GitHub over here:

https://github.com/AndyObtiva/nested_inherited_jruby_include_package

If you find this useful, feel free to install on your project and report any issues you may encounter. It is in early alpha mode. I am using on a couple of JRuby projects already.

No comments: