Hi Hiro,
Thank you very much. I got it to work by using include_class rather then
import as you suggested below (I must have done something wrong earlier
when I tried include_class myself).
Thank you again!!
— Den man 23/6/08 skrev Hirotsugu A. [email protected]:
Fra: Hirotsugu A. [email protected]
Emne: Re: [jruby-user] Problem calling Java from JRuby (using
non-default package)
Til: [email protected]
Dato: mandag 23. juni 2008 00.02
On Jun 22, 2008, at 2:19 PM, M C wrote:
I have problems calling (importing) Java in a non-defaut package.
Specifically, when I try the lines below in JRuby1.1.2 I get an error in
3’rd line “NameError: undefined local variable or method `ext’ for
main:Object”
 include Java
 require ‘jkeychain.jar’
 import Java::ext.jkeychain.JTest
I also tried “include_package” and “include_class” and removing the
“Java::” prefix with no sucess. The jar file contains the refered class
“ext.jkeychain.JTest” and is located in the current directory (current
dir is part of the classpath).
Anyone know what is wrong?
Thanks,
Morten
Are you saying that
include Javarequire 'jkeychain.jar’include_class
'ext.jkeychain.JTest’jtest = JTest.new
doesn’t work?
Here’s what I got:
$ jar tvf jkeychain.jar    0 Sun Jun 22 16:57:28 CDT 2008 META-INF/ Â
 95 Sun Jun 22 16:57:26 CDT 2008 META-INF/MANIFEST.MF   0 Sun Jun 22
16:57:28 CDT 2008 ext/Â Â Â 0 Sun Jun 22 16:57:28 CDT 2008
ext/jkeychain/Â Â 268 Sun Jun 22 16:57:28 CDT 2008
ext/jkeychain/JTest.class$ jirbirb(main):001:0> include Java=>
Objectirb(main):002:0> require ‘jkeychain.jar’=> trueirb(main):003:0>
include_class ‘ext.jkeychain.JTest’=>
[“ext.jkeychain.JTest”]irb(main):004:0> jtest = JTest.new=>
#<Java::ExtJkeychain::JTest:0xcfeb11
@java_object=ext.jkeychain.JTest@51b0af>
How about:
include Javarequire 'jkeychain.jar’JTest =
Java::ext.jkeychain.JTestjtest = JTest.new
That will get me:
$ jirbirb(main):001:0> include Java=> Objectirb(main):002:0> require
‘jkeychain.jar’=> trueirb(main):003:0> JTest =
Java::ext.jkeychain.JTest=> Java::ExtJkeychain::JTestirb(main):004:0>
jtest = JTest.new=> #<Java::ExtJkeychain::JTest:0x4957c7
@java_object=ext.jkeychain.JTest@94837a>
If you have Ola’s JRuby book handy, read page 101 carefully. Â As I read
it, to import a class, the top-level directory of your class must be
‘java’, ‘javax’, ‘org’ or ‘com’.
Hiro
Find din nye laptop på kelkoo.dk. Se de gode tilbud her -
http://dk.yahoo.com/r/pat/mm