javaenumsjrubyjruby-java-interop

Access enums from Jar file in Jruby


I'm trying to access the following static enum

public class Colors
{
    public enum ListofColors 
    {
        BLUE, RED, YELLOW
    }
}

But I keep getting the error

NameError: cannot load Java class Colors.Colors::ListofColors::BLUE

When I try the following:

CL = JavaUtilities.get_proxy_class('Colors.Colors::ListofColors::BLUE')

but then I tried the following:

CL = JavaUtilities.get_proxy_class('Colors.Colors')
red = Colors.Colors::ListofColors::RED

And it gave me the following error:

NameError: uninitialized constant Colors

Is there a different way to get this static enum from the jar file and include it in Jruby without getting that errpr?

Thanks.


Solution

  • I think you need package::class, you repeated Colors twice

    also see

    Problems Calling a Java Class from JRuby

    figure out if java_import helps you https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby

    Also you dont seem to be using the variable CL, Try using

    CL::ListofColors::Blue