Kelvin Wu wrote:
Kelvin,
Remember that Inline::Java will bind your code inside the calling package. This means
that you must access the code like this (notice the double PKG1::PKG1):
---- test1.pl --------- #!/usr/bin/perl
...
my $test = PKG1::PKG1->new($arg1, $arg2, $arg3); .... -------- test1.pl END ---------
---- PKG2.pm ------- package PKG2;
...
sub callpkg1 { my $test = PKG1::PKG1->new($arg1, $arg2, $arg3); ..... }
--------- PKG2.pm END ------
I tried it and it worked for me.
Patrick
Hi list,
I am new to Inline::Java. I have some problems when using Inline::Java.
I have PKG1.pm which is an adapter between jar and pm.
---------- PKG1.pm ---------- package PKG1;
use strict; use warnings;
BEGIN { $ENV{CLASSPATH} .= ":/path/to/my.jar"; $ENV{PERL_INLINE_DIRECTORY} = '/path/to/.Inline/'; }
use Inline Java => "DATA";
sub new { my $class = shift; return PKG1::PKG1->new(@_); }
1;
__DATA__ __Java__ import java.util.*; import java.io.*; import ...;
public class PKG1 { .....
--------- PKG1 END ----------
When I call this PKG1 directly from test1.pl, eg 'perl test1.pl', it works just fine.
---- test1.pl --------- #!/usr/bin/perl
use strict; use warnings; use PKG1;
my $test = PKG1->new($arg1, $arg2, $arg3); .... -------- test1.pl END ---------
However, If I use PKG1 from PKG2 which is another PM loaded by a main program, it didn't work at all.
---- PKG2.pm ------- package PKG2;
$|=1; use strict; use PKG1;
sub new { my $self = {}; bless $self; }
sub callpkg1 { my $test = PKG1->new($arg1, $arg2, $arg3); ..... }
sub send { my $self = shift; callpkg1(@_); ... } 1; --------- PKG2.pm END ------
test2.pl call PKG2, PKG2 call PKG1.
------- test2.pl ----------- require PKG2.pm; my $test2 = new PKG2; $test2->send($arg1, $arg2, $arg3); .... ------ test2.pl END ----
perl test2.pl didn't work.
I turn on the DEBUG o 5, it seems that Inline::Java hung at:
Thu Dec 16 04:12:59 2004 : [perl][3] match successful: score is 6 Thu Dec 16 04:12:59 2004 : Wide character in print at /usr/lib/perl5/site_perl/5.8.0/i586-linux-thread-multi/Inline/Java.pm line 1049. Thu Dec 16 04:12:59 2004 : [perl][3] creating object new PKG1(000, 8613701063045, "test") Thu Dec 16 04:12:59 2004 : [perl][3] packet sent is create_object PKG1 (java.lang.String,java.lang.String,java.lang.String) scalar:48.48.48 scalar:56.54.49.51.55.48.49.48.54.51.48.52.53 scalar:67.77.32.20013.25991.26631.39064 Thu Dec 16 04:12:59 2004 : [java][3] packet recv is create_object PKG1 (java.lang.String,java.lang.String,java.lang.String) scalar:48.48.48 scalar:56.54.49.51.55.48.49.48.54.51.48.52.53 scalar:67.77.32.20013.25991.26631.39064
and sometimes at:
Thu Dec 16 04:12:59 2004 : [java][4] class PKG1 is reference
Thu Dec 16 04:12:59 2004 : [java][3] found a PKG1 constructor
Thu Dec 16 04:12:59 2004 : [java][3] (java.lang.String,java.lang.String,java.lang.String) =
(java.lang.String,java.lang.String,java.lang.String)?
Thu Dec 16 04:12:59 2004 : [java][3] has matching signature
(java.lang.String,java.lang.String,java.lang.String)
Thu Dec 16 04:12:59 2004 : [java][4] arg 0 of signature is java.lang.String
Thu Dec 16 04:12:59 2004 : [java][4] class java.lang.String is
primitive string
Thu Dec 16 04:12:59 2004 : [java][4] args is scalar -> forcing to
java.lang.String
Thu Dec 16 04:12:59 2004 : [java][1] loading InlineJavaUserClassLink
via InlineJavaUserClassLoader
Thu Dec 16 04:12:59 2004 : [java][4] result is 000
Thu Dec 16 04:12:59 2004 : [java][4] arg 1 of signature is java.lang.String
Thu Dec 16 04:12:59 2004 : [java][4] class java.lang.String is
primitive string
Any idea? Thanks very much.
-- ===================== Patrick LeBoutillier Laval, Quebec, Canada