Forum: JRuby Import failing under 1.1.5 and 1.1.6RC1

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris W. (Guest)
on 2008-12-04 19:54
(Received via mailing list)
I have a class of the form "foo._2008_08_01.ClassName" and when I
require the file that has this import, I get the following error:

"NameError: cannot load Java class foo._2008_08_01"

I have tried with 1.1.5 and 1.1.6RC1 with the same results. Any idea
what might be going on here?

Thanks,
Chris
Charles Oliver N. (Guest)
on 2008-12-04 21:41
(Received via mailing list)
Chris W. wrote:
> I have a class of the form “foo._2008_08_01.ClassName” and when I
> require the file that has this import, I get the following error:
>
> “NameError: cannot load Java class foo._2008_08_01”
>
> I have tried with 1.1.5 and 1.1.6RC1 with the same results. Any idea
> what might be going on here?

Ugh....first smack whoever put that in the package name. Done? We can
move on now. :)

There are a few ways you should be able to access the class. Have you
tried import with "foo._2008_08_01.ClassName"? include_class? If neither
of those work we can find another way for you, probably something like
this:

cls = java.lang.Class.forName 'foo._2008_08_01.ClassName'
ClassName = JavaUtilities.get_proxy_class(cls)

If you can come up with specs (for <jruby>/spec/java_integration in
repo) we can look at making it work like you expect. File a bug.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Chris W. (Guest)
on 2008-12-04 22:12
(Received via mailing list)
Unfortunately, I don't have control over that package; though, I have
Java programs that call that package, so I think it's legal, if not
ugly.

I've tried import and include_class, and neither has worked. I think the
other suggestion won't work, because the class loader won't know that
class exists until I import it.

I'm happy to file a bug. What form should the specs take? Is the problem
that JRuby doesn't like a package beginning with an underscore,
containing an underscore? Numbers? Only numbers? Etc.

Are there any other suggestions? I have to ship this by the end of next
week :(

Thanks for your help,
Chris

On 12/4/08 11:40 AM, "Charles Oliver N." <removed_email_address@domain.invalid>
wrote:

Chris W. wrote:
> I have a class of the form "foo._2008_08_01.ClassName" and when I
> require the file that has this import, I get the following error:
>
> "NameError: cannot load Java class foo._2008_08_01"
>
> I have tried with 1.1.5 and 1.1.6RC1 with the same results. Any idea
> what might be going on here?

Ugh....first smack whoever put that in the package name. Done? We can
move on now. :)

There are a few ways you should be able to access the class. Have you
tried import with "foo._2008_08_01.ClassName"? include_class? If neither
of those work we can find another way for you, probably something like
this:

cls = java.lang.Class.forName 'foo._2008_08_01.ClassName'
ClassName = JavaUtilities.get_proxy_class(cls)

If you can come up with specs (for <jruby>/spec/java_integration in
repo) we can look at making it work like you expect. File a bug.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2008-12-04 22:36
(Received via mailing list)
There's a bunch of specs under spec/java_integration that should serve
as good examples.

Have you tried it against 1.1.6RC1? It seems to work ok for me here...

[headius @ cnutter:~/projects/jruby]
â—† cat foo/_2008_12_05/MyClass.java
package foo._2008_12_05;

public class MyClass {}
[headius @ cnutter:~/projects/jruby]
â—† javac foo/_2008_12_05/MyClass.java
[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import 'foo._2008_12_05.MyClass'; p
MyClass.new"
#<Java::Foo_2008_12_05::MyClass:0x5381298a
@java_object=foo._2008_12_05.MyClass@44594680>

Chris W. wrote:
>
>     >  require the file that has this import, I get the following error:
>     tried import with "foo._2008_08_01.ClassName"? include_class? If neither
>
>     ---------------------------------------------------------------------
>     To unsubscribe from this list, please visit:
>
>         http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Chris W. (Guest)
on 2008-12-04 22:49
(Received via mailing list)
Hmm, seems the underscores were confusing the interpreter. I’ve always
imported without quotes around the class name, but when I did (per your
example), it worked like a charm.

Thanks for your help.

-chris

On 12/4/08 12:36 PM, "Charles Oliver N." <removed_email_address@domain.invalid>
wrote:

There's a bunch of specs under spec/java_integration that should serve
as good examples.

Have you tried it against 1.1.6RC1? It seems to work ok for me here...

[headius @ cnutter:~/projects/jruby]
â—† cat foo/_2008_12_05/MyClass.java
package foo._2008_12_05;

public class MyClass {}
[headius @ cnutter:~/projects/jruby]
â—† javac foo/_2008_12_05/MyClass.java
[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import 'foo._2008_12_05.MyClass'; p
MyClass.new"
#<Java::Foo_2008_12_05::MyClass:0x5381298a
@java_object=foo._2008_12_05.MyClass@44594680>

Chris W. wrote:
>
>     >  require the file that has this import, I get the following error:
>     tried import with "foo._2008_08_01.ClassName"? include_class? If neither
>
>     ---------------------------------------------------------------------
>     To unsubscribe from this list, please visit:
>
>         http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2008-12-04 23:34
(Received via mailing list)
Chris W. wrote:
> Hmm, seems the underscores were confusing the interpreter. I’ve always
> imported without quotes around the class name, but when I did (per your
> example), it worked like a charm.

Confirmed...can you file a bug for this pleeeeez?

[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import foo._2008_12_05.MyClass; p
MyClass.new"
-e:1: undefined local variable or method `foo' for main:Object
(NameError)
[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import Java::foo._2008_12_05.MyClass; p
MyClass.new"
/Users/headius/projects/jruby/lib/ruby/site_ruby/1.8/builtin/java/ast.rb:49:in
`get_proxy_or_package_under_package': cannot load Java class
foo._2008_12_05 (NameError)
  from
/Users/headius/projects/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:43:in
`method_missing'
  from -e:1

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Chris W. (Guest)
on 2008-12-05 00:07
(Received via mailing list)
http://jira.codehaus.org/browse/JRUBY-3218. Thanks as always for your
help, Charles. I’ll try to make the problem more interesting next time
:)

-chris


On 12/4/08 1:33 PM, "Charles Oliver N." <removed_email_address@domain.invalid>
wrote:

Chris W. wrote:
> Hmm, seems the underscores were confusing the interpreter. I’ve always
> imported without quotes around the class name, but when I did (per your
> example), it worked like a charm.

Confirmed...can you file a bug for this pleeeeez?

[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import foo._2008_12_05.MyClass; p
MyClass.new"
-e:1: undefined local variable or method `foo' for main:Object
(NameError)
[headius @ cnutter:~/projects/jruby]
â—† CLASSPATH=. jruby -rjava -e "import Java::foo._2008_12_05.MyClass; p
MyClass.new"
/Users/headius/projects/jruby/lib/ruby/site_ruby/1.8/builtin/java/ast.rb:49:in
`get_proxy_or_package_under_package': cannot load Java class
foo._2008_12_05 (NameError)
        from
/Users/headius/projects/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:43:in
`method_missing'
        from -e:1

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.