[Brisbane-pm] Calling java method from a perl program

Robert Loomans robertl at apnic.net
Tue Sep 11 00:42:16 PDT 2007


Tony Obermeit wrote:
> I need to call a static java method (no java object instantiation  
> required) from a perl script.  Based on my googling of the topic, it  
> seems there are a number of ways to do this.  The java code is  
> compiled and cannot be embedded within the perl script (so  
> Inline::Java isn't appropriate)....

I don't believe that only having a class file excludes Inline::Java.

You can either tell Inline::Java to study the enclosing class:

use Inline (
      Java => 'STUDY',
      STUDY => ['your.class.name.here'],
      AUTOSTUDY => 1,
);

your::class::name::here::method_name(args);

...or you can write your own wrapper code using Inline::Java that calls
the method and call the wrapper from Perl.

> Any suggestions as to the pros / cons of the various options?

When I had to do this, we weren't able to get Inline::Java to work
(proprietary Corba client libraries that needed to override built in
classes.... ick) so we wrote a small server that listened on a TCP
socket and accepted commands (eg, "provision 123.123.4.5 username
password you_are_an_eggbeater")... but don't go there if Inline::Java
works it's clunky and fragile.

Another thought: you could use XMLRPC... but that might be over-kill :)

Rob

-- 
Robert Loomans                                 Email:  robertl at apnic.net
Senior Programmer/Analyst, APNIC               Phone:    +61 7 3858 3100
http://www.apnic.net                             Fax:    +61 7 3858 3199
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3818 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.pm.org/pipermail/brisbane-pm/attachments/20070911/5d20daf7/attachment.bin 


More information about the Brisbane-pm mailing list