|
What is usual library to call
java from Perl?
Answer: Inline-Java is the usual library to call java from Perl, and this propose a org.perl.java module which should allow calling Perl from Java. However, because of the unpredictability of the JNI implementations for different JVMs it is difficult to say what combinations of JVM and Perl will work. Typically, what is required is Perl with MULTIPLICITY, and threads compiled in. That means he uses a custom built Perl. Otherwise, Inline::Java::Callback allows you to call Perl functions from Java. To do this you need to create an org.perl.inline.java.InlinePerlCaller object. Here is a example of a typical use: use Inline Java => <<END ; import java.util.* ; import org.perl.inline.java.* ;
class Pod_regexp extends InlineJavaPerlCaller { public Pod_regexp() throws InlineJavaException { }
throws InlineJavaException { try { String m = (String)CallPerlSub("main::regexp", new Object [] {target, pattern}) ;
return true ; } } catch (InlineJavaPerlException pe){ // $@ is in pe.GetObject() }
return false ; } } END
my $re = new Pod_regexp() ; my $match = $re->match("Inline::Java", "^Inline") ; print($match . "n") ; # prints 1
sub regexp { my $target = shift ; my $pattern =
shift ;
return ($target =~ /$pattern/) ; } |
|
See also
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|