Error while using include_class

Hi All,

I am attempting to use a third party java class in a script. Simply
using a
include_class on the classname throws the following error:

C:\work\jruby\xel>c:\jruby-1.0.1\bin\jruby.bat test.rb :1:in each': wrong constant name tcUtilityFactory (NameError) from file:/C:/jruby-1.0.1/lib/jruby.jar!/builtin/javasupport/core_ext/object.rb:28:ininclude_class’
from :1

My script is very simple:

require ‘java’
include_class ‘Thor.API.tcUtilityFactory’
puts “foo”

I am using JRuby 1.0.1 on Windows XP.

I would appreciate any pointers towards this issue. Google does not seem
to
be helpful.

Thanks!
Amol

If I remember correctly, Ruby constants have to start with an upper
case, so your java class by the name of tcUtilityFactory won’t work.

Try using the Java::Thor.API.tcUtilityFactory.foo() and see if that
works.

Peter

Amol Dharmadhikari अमोल् धर्माधीकारि wrote:

`include_class’

I would appreciate any pointers towards this issue. Google does not
seem to be helpful.

Thanks!
Amol

Hi,

You’ll need to change that class name. Since it doesn’t follow standard
Java practices in naming, our code doesn’t handle it correctly either.
To rename it specifically:

require ‘java’
include_class(‘Thor.API.tcUtilityFactory’) {|pkg, name|
“TCUtilityPackage”}
puts “foo”
puts TCUtilityPackage.java_class

Cheers


Ola B. (http://ola-bini.blogspot.com)
JRuby Core Developer
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

“Yields falsehood when quined” yields falsehood when quined.


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email