Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] Calling Java from Ruby

Thanks, Alex.  It works with an augmented CLASSPATH in jruby.bat.

Is that where you modified CLASSPATH too? I was hoping for a more elegant interface in an Eclipse dialog box...

--Andy


Alex Panchenko wrote:
Hi Andrew,

You should specify the CLASSPATH environment variable to the location the java files could be loaded from.
Most probably it should be C:\Workspace\ZooGlue\bin in your example.

I have looked at http://jruby.codehaus.org/Java+Integration and made some changes in your script, so not it works for me. Probably there are other ways to do the same thing.

include Java
include_class 'zoo.utils.Truthiness'

def show(it)
puts it.to_s + ":\t" + Truthiness::isTrue(it).to_s + "\t" + Truthiness::isFalse(it).to_s
puts "\t" + (it ? "true":"false") + "\t" + ((!it)?"true":"false")
end

0 ? "TRUE" : "FALSE"

show( true )
show( false )
show( 0 )
show( 1 )
show( nil )
show( "bye" )
show( "" )
show( 'x' )

Regards,
Alex


Andrew Mickish wrote:
How can I call static Java methods located in a different project than my Ruby script?

I have a Java project named ZooGlue containing the class zoo.util.Truthiness, and a Ruby project named Zuby containing the script TestTruthiness.rb starting with these lines:

   include Java
   include_class Java::zoo.utils.Truthiness

When I run TestTruthiness.rb, I get
C:/downloads/Ruby/jruby-1.1.4/lib/ruby/site_ruby/1.8/builtin/javasupport.rb:49: in `method_missing': cannot load Java class zoo.utils.Truthiness (NameError)
   from C:\Workspace\Zuby\TestTruthiness.rb:9

I probably ought to put ZooGlue on Zuby's build path somehow, but the Build Path dialog box for the Ruby project does not list any of my Java projects as eligible to add to the build path. Should I explicitly refer to C:\Workspace\ZooGlue\bin\zoo\utils\Truthiness.class in the Ruby script somehow?

I am using Eclipse 3.4, DLTK 9.5, and my Ruby Interpreter executable is C:\downloads\Ruby\jruby-1.1.4\bin\jruby.bat

######################################################################
# Project: Zuby
# File: TestTruthiness.rb

include Java
include_class Java::zoo.utils.Truthiness

def show(it)
 println "" + it + ":\t" + isTrue(it) + "\t" + isFalse(it);
 println "\t" + (it ? "true":"false") + "\t" + ((!it)?"true":"false")
end

0 ? "TRUE" : "FALSE"

show( true )
show( false )
show( 0 )
show( 1 )
show( null )
show( "bye" )
show( "" )
show( 'x' )

######################################################################

//////////////////////////////////////////////////////////////////////
// Project: ZooGlue
// File: Truthiness.java

package zoo.utils;

/**
* Everything is true except false and null.
*/
public class Truthiness {
     static public boolean isFalse (Object o)
   {
       return o == null || Boolean.FALSE.equals(o);
   }

   static public boolean isTrue (Object o)
   {
       return isFalse(o) == false;
   }
}

//////////////////////////////////////////////////////////////////////


_______________________________________________
dltk-dev mailing list
dltk-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dltk-dev
_______________________________________________
dltk-dev mailing list
dltk-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dltk-dev



Back to the top