How do I include my own java classes?

Hello List,

Today I am learning how to mix .java files with JRuby.

I want to jump a barrier which should be fairly low for most of you.

I have a file: MyClass.java

Here is what is in it:

public class MyClass {}

I compiled it with this shell command: javac MyClass.java

I have a Ruby file: include_myclass.rb

Here is what is in it:

#!/usr/bin/env jruby

include_myclass.rb

require ‘java’

include_class MyClass

class IncludeMyclass
def hello
p “hello”
end
end

IncludeMyclass.new.hello

I don’t understand why the
include_class MyClass
declaration gives me an error.

I am seeing this:

Fri Aug 06 19:24 /pt/b/jruby maco$
Fri Aug 06 19:24 /pt/b/jruby maco$ javac MyClass.java
Fri Aug 06 19:25 /pt/b/jruby maco$
Fri Aug 06 19:25 /pt/b/jruby maco$
Fri Aug 06 19:25 /pt/b/jruby maco$ jruby include_myclass.rb
include_myclass.rb:7: uninitialized constant MyClass (NameError)
Fri Aug 06 19:25 /pt/b/jruby maco$
Fri Aug 06 19:25 /pt/b/jruby maco$
Fri Aug 06 19:25 /pt/b/jruby maco$

How do I force
include_myclass.rb
to “see” MyClass.class ?

thanks


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Aug 6, 2010, at 10:29 PM, Audrey L. wrote:

public class MyClass {}

IncludeMyclass.new.hello
Fri Aug 06 19:24 /pt/b/jruby maco$ javac MyClass.java
to “see” MyClass.class ?

In your include_myclass.rb, MyClass is a constant. In order to tell
jruby to read the content of the class file, include_class needs a
string as the argument, i.e.:

include_class ‘MyClass’

thanks


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

include_class ‘MyClass’

Works good!


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email