[jruby-dev] Class.ForName in java

1 view
Skip to first unread message

Tim Chen

unread,
Feb 15, 2011, 1:51:28 AM2/15/11
to d...@jruby.codehaus.org
Hi all,

I'm currently trying to use JRuby to launch our Java application, and I'm currently just calling the command line jruby with all the dependencies passed in as classpath and launching it in a Ruby script.

ex: jruby -J-cp xxxxx/.jar:xxxxxx.jar run.rb

The problem is that part of our app downloads yaml files and deserializes it to objects based on the type specified in each field, and it calls Class.forName('org.my.class') to
try to get the class and call its constructor.

However, calling the java app from JRuby gives NoClassFound when calling Class.forName, even though the class is in one of the jar files passed in the classpath.

I wonder what's the way to get the class loader to able to find that class?

Thanks,

Tim

David Calavera

unread,
Feb 15, 2011, 4:32:24 AM2/15/11
to d...@jruby.codehaus.org
Hi Tim,

the problem is that the -J-cp option sets the classpath for the java process rather than the jruby one. Last week I wrote a post about class loaders in jruby that might help you:


Cheers

Timothy Chen

unread,
Feb 15, 2011, 4:59:07 PM2/15/11
to d...@jruby.codehaus.org
Thanks! That's exactly what I needed.

Tim

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages