Error "cannot load Java class"

Discussion in 'Ruby' started by Ahmed Abdelsalam, Apr 23, 2009.

  1. 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 !!!
    --
    Posted via http://www.ruby-forum.com/.
     
    Ahmed Abdelsalam, Apr 23, 2009
    #1
    1. Advertising

  2. Ahmed Abdelsalam

    Chuck Remes Guest

    On Apr 23, 2009, at 5:22 AM, Ahmed Abdelsalam wrote:

    > 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)


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

    cr
     
    Chuck Remes, Apr 23, 2009
    #2
    1. Advertising

  3. Chuck Remes wrote:
    > On Apr 23, 2009, at 5:22 AM, Ahmed Abdelsalam 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")));
    --
    Posted via http://www.ruby-forum.com/.
     
    Ahmed Abdelsalam, Apr 23, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,732
  2. JavaQueries
    Replies:
    1
    Views:
    3,752
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,178
  4. Bishop
    Replies:
    1
    Views:
    820
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,075
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page