Problem calling Java from JRuby (using non-default package)

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

  Trænger du til at se det store billede? Kelkoo giver dig gode 

tilbud på LCD TV! Se her http://dk.yahoo.com/r/pat/lcd

You can type code like this:
include java
import ext.jkeychain.JTest

The java class in JRuby is Java::ExtJkeychain::JTest

2008/6/23 M C [email protected]:

No, won’t work. I get the same exception in line 2 if I omit “Java::” as
in your example.

— Den søn 22/6/08 skrev dennis zhuang [email protected]:
You can type code like this:
include java
import ext.jkeychain.JTest

The java class in JRuby is Java::ExtJkeychain::JTest

2008/6/23 M C [email protected]:

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

FÃ¥ en billig laptop. Se Kelkoos gode tilbud her!

  ________________________________________________________

Audi, Fiat, Peugeot, Skoda, Porsche, Toyota, Ford - Kelkoo har brugte
biler til en hver smag! Klik her for at sammenligne
priser.(http://dk.yahoo.com/r/pat/mmb)

On Jun 22, 2008, at 2:19 PM, M C wrote:

“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 Java
require ‘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
$ jirb
irb(main):001:0> include Java
=> Object
irb(main):002:0> require ‘jkeychain.jar’
=> true
irb(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 Java
require ‘jkeychain.jar’
JTest = Java::ext.jkeychain.JTest
jtest = JTest.new

That will get me:

$ jirb
irb(main):001:0> include Java
=> Object
irb(main):002:0> require ‘jkeychain.jar’
=> true
irb(main):003:0> JTest = Java::ext.jkeychain.JTest
=> Java::ExtJkeychain::JTest
irb(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

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