# Error "cannot load Java class"

**URL:** <https://rubytalk.org/t/error-cannot-load-java-class/53009>\
**Category:** ruby-talk\
**Created:** [23 April 2009 10:22 UTC](https://rubytalk.org/t/error-cannot-load-java-class/53009 "2009-04-23T10:22:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Abdelsalam](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Ahmed\_Abdelsalam](https://rubytalk.org/u/Ahmed_Abdelsalam)\
**Post date:** [23 April 2009 10:22 UTC](https://rubytalk.org/t/error-cannot-load-java-class/53009/1 "2009-04-23T10:22:05Z")

</div>

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  
&nbsp;&nbsp;at  
com.sun.script.jruby.JRubyScriptEngine.evalNode(JRubyScriptEngine.java:456)  
&nbsp;&nbsp;at  
com.sun.script.jruby.JRubyScriptEngine.eval(JRubyScriptEngine.java:186)  
&nbsp;&nbsp;at javax.script.AbstractScriptEngine.eval(Unknown Source)

Caused by: org.jruby.exceptions.RaiseException: cannot load Java class  
com.ch.Cells  
&nbsp;&nbsp;at (unknown).(unknown)(/builtin/java/ast.rb:49)  
&nbsp;&nbsp;at  
(unknown).get\_proxy\_or\_package\_under\_package(/builtin/javasupport/java.rb:51)  
&nbsp;&nbsp;at #\<Class:01x965654\>.method\_missing(\<unknown\>:1)  
&nbsp;&nbsp;at (unknown).(unknown)(:1)

Any help !!!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Chuck\_Remes](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@Chuck\_Remes](https://rubytalk.org/u/Chuck_Remes)\
**Post date:** [23 April 2009 16:15 UTC](https://rubytalk.org/t/error-cannot-load-java-class/53009/2 "2009-04-23T16:15:37Z")

</div>

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

cr

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

---

<div class="post-metadata">

**Author:** ![Ahmed\_Abdelsalam](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Ahmed\_Abdelsalam](https://rubytalk.org/u/Ahmed_Abdelsalam)\
**Post date:** [23 April 2009 16:51 UTC](https://rubytalk.org/t/error-cannot-load-java-class/53009/3 "2009-04-23T16:51:46Z")

</div>

Chuck Remes 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  
&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;@cells = {'a1' =\> 'Hello a1'};  
&nbsp;&nbsp;end  
end

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

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

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//get jruby engine  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScriptEngine jruby = m.getEngineByName("jruby");  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//process a ruby file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jruby.eval(new BufferedReader(new FileReader("... path to ruby  
file")));

> **···**
>
> > On Apr 23, 2009, at 5:22 AM, Ahmed Abdelsalam wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
