Jruby classpath question

I can’t set the classpath to save my life! First, quick demo to prove
that the class is compiled and located correctly.

$ irb
bin> require ‘java’
=> true
bin> $CLASSPATH
=> []
bin> com.calendar.CalendarEvent
=> Java::ComCalendar::CalendarEvent

Now let’s cd to the parent directory and add the child to the
classpath. Should still work, right?

$ irb
20110218> require ‘java’
=> true
20110218> $CLASSPATH << ‘bin’
=> [“file:bin”]
20110218> com.calendar.CalendarEvent
NameError: cannot load Java class com.calendar.CalendarEvent
from
/Users/sbronson/.rvm/rubies/jruby-1.5.6/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:51:in
`method_missing’
from (irb):4
20110218>

Any idea what’s going wrong here?

Also, should I be worried that “file:bin” is on the classpath when bin
is a directory?

Thanks!

- Scott

Should it be this instead? I think it wants bin to be a file, not a
folder
if you don’t include the slash.

$CLASSPATH << ‘bin/’

Joe

Joseph A. wrote in post #990409:

Should it be this instead? I think it wants bin to be a file, not a
folder
if you don’t include the slash.

$CLASSPATH << ‘bin/’

That will work. Alternatively, you can just set CLASSPATH env variable
and it will be recognised by jruby. You do not have to modify $CLASSPATH
from the prompt (if you are just checking out how to set $CLASSPATH from
irb, disregard my answer).

Joe

On Fri, Apr 1, 2011 at 11:44 AM, Radhesh K. removed_email_addres[email protected]
wrote:

from the prompt (if you are just checking out how to set $CLASSPATH from
irb, disregard my answer).

That’s true, it does work. How weird that a trailing slash is required!

~/20110218$ irb -rjava
jruby-1.5.6 :001 > $CLASSPATH << ‘bin/’
=> [“file:bin/”]
jruby-1.5.6 :002 > com.calendar.CalendarEvent
=> Java::ComCalendar::CalendarEvent

Notice that the path is still “file:bin/” even though bin is a
directory.

Also weird, the trailing slash is NOT required when setting via
environment variable:

~20110218$ CLASSPATH=bin irb -rjava
jruby-1.5.6 :001 > com.calendar.CalendarEvent
=> Java::ComCalendar::CalendarEvent

Why is it that Java’s classpath never works the way I would expect??

- Scott

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