Accessing a .class

Hi,

How do you access a .class placed, say, in the directory as the .rb?

I read Eric A.'s piece:

http://www.artima.com/weblogs/viewpost.jsp?thread=214719

but this didn’t seem to contain the answer.

I also found this:

http://www.headius.com/jrubywiki/index.php/Calling_Java_from_JRuby

but this didn’t seem to help either.

Somewhere else, I found the suggestion to do something like:

$CLASSPATH << “.”
include_class ‘Dino’
a = Dino.new

But this returns:

:1:in eval': cannot load Java class Dino (NameError) from file:/D:/jruby/lib/jruby.jar!/builtin/javasupport/core_ext/object.rb:52: ininclude_class’
from :1:in each' from file:/D:/jruby/lib/jruby.jar!/builtin/javasupport/core_ext/object.rb:28: ininclude_class’
from :1

What is the canonical method for accessing class files?


Cheers,
Marc


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Can you set the CLASSPATH to include your class directory before
invoking jruby?

I had just gotten caught by the same thing last week. Check out the
FAQ at http://www.headius.com/jrubywiki/index.php/FAQs

See: How come Java can’t find resources in class folders that I’ve
appended to the $CLASSPATH global variable at runtime?

-lenny

On Sep 28, 2007, at 2:24 PM, marc wrote:

I also found this:

object.rb:28:

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

On Sep 30, 2007, at 1:16 PM, marc wrote:

$CLASSPATH << “C:/Documents and Settings/Marc/My Documents/jruby/”

soon gets ugly :-o

I appreciate I can’t do this with a CLASSPATH, hence the question.

Thanks again.

Not sure if its what you’re looking for, but you can do something like:
$CLASSPATH << File.expand_path(’.’)} + “/”
or
$CLASSPATH << File.expand_path(File.dirname(FILE) + “/”.

Just be aware that File.expand_path seems to always cut off trailing
slashes so make sure to append in afterward.

-lenny


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Lenny M. said…

but this didn’t seem to contain the answer.
include_class ‘Dino’
from
See: How come Java can’t find resources in class folders that I’ve
appended to the $CLASSPATH global variable at runtime?

Thanks, Lenny. This works - on both Linux and Windows - with absolute
paths, so I’m moving.

I’d still like to know whether there is a way of referencing the current
dir, since this would make scripts a bit more portable. Also,
referencing

$CLASSPATH << “/home/marc/juby/”

isn’t too bad, but

$CLASSPATH << “C:/Documents and Settings/Marc/My Documents/jruby/”

soon gets ugly :-o

I appreciate I can’t do this with a CLASSPATH, hence the question.

Thanks again.


Cheers,
Marc


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Lenny M. said…

Thanks again.

Not sure if its what you’re looking for, but you can do something like:
$CLASSPATH << File.expand_path(’.’)} + “/”
or
$CLASSPATH << File.expand_path(File.dirname(FILE) + “/”.

Just be aware that File.expand_path seems to always cut off trailing
slashes so make sure to append in afterward.

Nice one. Thanks.


Cheers,
Marc


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. said…

marc wrote:

How do you access a .class placed, say, in the directory as the .rb?

Java classes can’t just be moved around, unfortunately; they also have
to be placed in a directory structure that maps to their package
structure.

Sure. I’m just trying to get things going outwith the jdk classes -
which worked fine from the start - and decided to start with a simple
class of my own making. The help I’ve received has been successful.
Thanks.

If they have no package, you can point CLASSPATH at the
containing directory and they should load. If they have a package
structure of org.foo.bar.Something, the Something.class file must be in
a directory org/foo/bar/ and you would point CLASSPATH at the directory
above org.

Yup, I’ve moved onto this now.


Cheers,
Marc


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

marc wrote:

Hi,

How do you access a .class placed, say, in the directory as the .rb?

Java classes can’t just be moved around, unfortunately; they also have
to be placed in a directory structure that maps to their package
structure. If they have no package, you can point CLASSPATH at the
containing directory and they should load. If they have a package
structure of org.foo.bar.Something, the Something.class file must be in
a directory org/foo/bar/ and you would point CLASSPATH at the directory
above org.

Can you give any more information about the class you’re trying to load?

  • Charlie

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs