Hi,
I’m trying to extend a java class in ruby, from everything I’ve read and
been told, this should work… but it isn’t. Am I missing something
simple?
Note: the jar file is in the same directory as the ruby file.
java class (compiled and put into a jar):
package tv.domain;
public class MyJavaClass {
public String getName() {
return “foo”;
}
}
ruby class:
require ‘java’
require ‘myjar.jar’
import ‘tv.domain.MyJavaClass’
class MyRubyClass < MyJavaClass
end
rc = MyRubyClass.new
puts rc.getName
run this and I got:
: cannot link Java class tv.domain.MyJavaClass (NameError)
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Hi Jay,
Your example work here just fine:
- edit MyJavaClass.java
- javac -d . MyJavaClass.java
- jar cvf myjar.jar tv/
Both MyJavaClass.java and rb files as in your case.
puts rc.getName prints foo.
Looking at the error message, maybe you actual case a bit more
complicated
and MyJavaClass depends on other java classes that are not loaded and
are not in
the classpath?
Try to run your example with jruby -d your_file.rb and see if it gives
you more information, especially java exceptions that explain what’s
wrong in your setup.
Thanks,
–Vladimir
On Fri, Jun 27, 2008 at 5:08 AM, Jay McGaffigan
[email protected] wrote:
public String getName() {
import ‘tv.domain.MyJavaClass’
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Thanks Vladimir,
It appears (thanks to your help) that my java code was compiled with
Java
1.6 and my java home was pointing to 1.5
UGH!
That was the problem.
Thanks again… for your help, patience and kindess