Hi Charlie,
The main method defined in a ruby class is not generated properly by
the jrubyc utility. I mean the function has different signature than
expected by the JVM:
public static Object main(Object args)
while the JVM looks for a different signature:
public static void main(String[] argv)
But anyways, I can write the right main method inside the jrubyc
generated .java file and when running, it is ok.
Best wishes,
Ahmed Nabhan
Quoting Charles Oliver Nutter <head...@headius.com>:
On Tue, Mar 16, 2010 at 10:39 AM, Ahmed Ragab Nabhan <anab...@uvm.edu> wrote:
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:
$ 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.<clinit>(MyRubyClass.java:18)
I replied to your other email about this issue...and then found that I
still had a bug. I've fixed that now (in r12816f3)
We should probably file a bug to provide a better error message when
the class can't be found. Maybe you could do that?
You should also know that your MyRubyClass in myruby.rb does not
define a "main" Java method, so you'll get an error like this:
~/projects/jruby ➔ java -cp .:lib/jruby.jar MyRubyClass
Exception in thread "main" java.lang.NoSuchMethodError: main
If you define a main method like so:
require 'java'
class MyRubyClass
java_signature "void main(String[])"
def self.main(args)
MyRubyClass.new.helloWorld
end
def helloWorld
puts "Hello from Ruby"
end
end
It should work fine:
~/projects/jruby ➔ java -cp .:lib/jruby.jar MyRubyClass
Hello from Ruby
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email