Hi JRuby users,
I have used the simple utility jrubyc that compiles a .rb file into
.java. When I try to
run the resulting .class file, I got got an exception:
A very simple jruby file is used to declare a class. Then, I write a
main method inside
the generated java code in order to instantiate an object and call
method. Here is a code
snippet:
#myruby.rb
class MyRubyClass
def helloWorld
puts “Hello from Ruby”
end
end
$ jrubyc --java myruby.rb
javac -d /Users/anabhan/Work/Workspace/JavaRuby -cp
/Users/anabhan/.rvm/rubies/jruby-head/lib/jruby.jar:. MyRubyClass.java
$ java -cp /.rvm/rubies/jruby-head/lib/jruby.jar:. MyRubyClass
Exception in thread “main” java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at MyRubyClass.(MyRubyClass.java:18)
12: private static final Ruby ruby = Ruby.getGlobalRuntime();
13: private static final RubyClass metaclass;
14:
15: static {
16:
17: RubyClass metaclass = ruby.getClass(“MyRubyClass”);
18: metaclass.setClassAllocator(MyRubyClass.class);
19: if (metaclass == null) throw new NoClassDefFoundError(“Could
not load Ruby
20: class: MyRubyClass”);
21: metaclass = metaclass;
22: }
The problem is that the ruby.getClass(“MyRubyClass”) returns null.
I checked that the
method Ruby.getGlobalRuntime() returns a not-null object.
Any idea about what is going wrong?
Thank you,
Ahmed Nabhan
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email