Forum: Ruby Error "cannot load Java class"

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.
Ahmed A. (Guest)
on 2009-04-23 14:22
I've created two java classes that I'm trying to call from ruby file. I
put the java classes with the ruby file in the same directory, and tried
to run.

I accessed java classes from the ruby file using full class path like:
Java::com.ch.Cells

but I got the following error:
 org.jruby.exceptions.RaiseException: cannot load Java class
com.ch.Cells
  at
com.sun.script.jruby.JRubyScriptEngine.evalNode(JRubyScriptEngine.java:456)
  at
com.sun.script.jruby.JRubyScriptEngine.eval(JRubyScriptEngine.java:186)
  at javax.script.AbstractScriptEngine.eval(Unknown Source)

Caused by: org.jruby.exceptions.RaiseException: cannot load Java class
com.ch.Cells
  at (unknown).(unknown)(/builtin/java/ast.rb:49)
  at
(unknown).get_proxy_or_package_under_package(/builtin/javasupport/java.rb:51)
  at #<Class:01x965654>.method_missing(<unknown>:1)
  at (unknown).(unknown)(:1)


Any help !!!
Chuck R. (Guest)
on 2009-04-23 20:17
(Received via mailing list)
On Apr 23, 2009, at 5:22 AM, Ahmed A. wrote:

> org.jruby.exceptions.RaiseException: cannot load Java class
> Caused by: org.jruby.exceptions.RaiseException: cannot load Java class
> com.ch.Cells
>  at (unknown).(unknown)(/builtin/java/ast.rb:49)
>  at
> (unknown).get_proxy_or_package_under_package(/builtin/javasupport/
> java.rb:51)
>  at #<Class:01x965654>.method_missing(<unknown>:1)
>  at (unknown).(unknown)(:1)

You need to show us the code too. Show the Java and show the ruby.

cr
Ahmed A. (Guest)
on 2009-04-23 20:51
Chuck R. wrote:
> On Apr 23, 2009, at 5:22 AM, Ahmed A. wrote:
>
>> org.jruby.exceptions.RaiseException: cannot load Java class
>> Caused by: org.jruby.exceptions.RaiseException: cannot load Java class
>> com.ch.Cells
>>  at (unknown).(unknown)(/builtin/java/ast.rb:49)
>>  at
>> (unknown).get_proxy_or_package_under_package(/builtin/javasupport/
>> java.rb:51)
>>  at #<Class:01x965654>.method_missing(<unknown>:1)
>>  at (unknown).(unknown)(:1)
>
> You need to show us the code too. Show the Java and show the ruby.
>
> cr

Here is the ruby code:
class Cells < Java::cz.cesnet.meta.jruby.Cells
  def initialize
    @cells = {'a1' => 'Hello a1'};
  end
end

here is the java code:
ScriptEngineManager m = new ScriptEngineManager();

     // Override due to classpath troubles with OSGi ?
     m.registerEngineName("jruby",
         new com.sun.script.jruby.JRubyScriptEngineFactory());

     //get jruby engine
       ScriptEngine jruby = m.getEngineByName("jruby");
       //process a ruby file
       jruby.eval(new BufferedReader(new FileReader("... path to ruby
file")));
This topic is locked and can not be replied to.