Search code examples
rubyjruby

Imported classes from a jar file in JRuby conflict with top level core module


I have a JRuby project that is requiring a third-party .jar file containing several Java classes that I need to use. I am running into an issue where one of the classes is named Process which is conflicting with the top level Ruby Process module.

I have built a github repository with a minimal proof of concept that illustrates the issue: https://github.com/douglasmiller/process_test

Has anyone else encountered a similar issue? What can I do to resolve this?


Solution

  • similar to what you would do in Ruby to solve this - import it under a module (where it's used) or do not import it at all.

    1. do not use java_import org.process_test.Process and use org.process_test.Process::PROCESS_CONSTANT directly

    2. if you really want to import only import where it won't conflict :

    module MyApp java_import org.process_test.Process # MyApp::Process != ::Process class ProcessStuff def initialize; puts Process::PROCESS_CONSTANT end end end