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: in include_class’
from :1:in each' from file:/D:/jruby/lib/jruby.jar!/builtin/javasupport/core_ext/object.rb:28: in include_class’
from :1
What is the canonical method for accessing class files?
$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.
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.
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.
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.
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.