Forum: JRuby how to require a straight '.class' file

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.
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2010-09-09 04:09
I'm familiar with how to require jar files, but I can't seem to quite be
able to figure out how to reference a class like this:


>> Dir['**/*.class']
=>
["target/classes/org/familysearch/digitalarchive/tapeingestreader/Boolean2.class"]

no incantation of $: and java_import seem to work.

Is this possible currently (require a straight .class file)?

Thanks.
-r
4cd5248cc6250b23d83f74945c220732?d=identicon&s=25 David Yang (Guest)
on 2010-09-09 04:21
(Received via mailing list)
On Sep 8, 2010, at 10:09 PM, Roger Pack wrote:

> I'm familiar with how to require jar files, but I can't seem to quite be
> able to figure out how to reference a class like this:
>

Hi Roger - I struggled with this for a while as well.  This is what
works for me.

Let's say I have 'myclass.class' which has a class called 'myclass' in
'mypackage.myclass'.  This causes two problems because JRuby doesn't
like non-Camelcased classes (because Modules have to have cap-Alpha
starts I think).

First, create a directory (under lib/ for example - though not
necessary) called mypackage and put myclass.class in there.

Then this should work:

require 'java'
$CLASSPATH << 'lib'

myclass = JavaUtilities.get_proxy_class('mypackage.myclass')

@myclass  = myclass.new

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

    http://xircles.codehaus.org/manage_email
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2010-09-09 19:09
> require 'java'
> $CLASSPATH << 'lib'
>
> myclass = JavaUtilities.get_proxy_class('mypackage.myclass')

Many thanks.
The following seems to work:

>> $CLASSPATH<<'target/classes'
=>
["file:/C:/dev/digitalarchive_trunk/dax/tapeingestreader/target/classes/"]
>> import org.familysearch.digitalarchive.tapeingestreader.Boolean2

(where file
"target/classes/org/familysearch/digitalarchive/tapeingestreader/Boolean2.class"
exists)

It surprised me that (it appears) that $LOAD_PATH is searched for jar
files but not for .class files (?)

I would have originally expected that doing the following would work:
$: << 'target/classes'
java_import org.familysearch.digitalarchive.tapeingestreader.Boolean2

So...should I report this as a feature request? Or is it "the way it's
supposed to be and going to be" already?

-r
This topic is locked and can not be replied to.