Call Java from Perl

   Print.Print
Email.Email weblog link
Blog this.Blog this

Nat Torkington
Mar. 22, 2001 07:12 PM
Permalink

Atom feed for this author. RSS 1.0 feed for this author. RSS 2.0 feed for this author.

URL: http://search.cpan.org/search?module=Inline::Java...

Fresh onto CPAN is Inline::Java. The Inline modules let you write code in another programming language, but call the subroutines from Perl. The Inline concept has been well received as an alternative to the complicated XS programming system, and the presentations at the German Perl Workshop were very well received (there will be presentations at The Perl Conference, and probably one of the YAPCs too).

Inline::Java, as you might guess, lets you access Java objects from Perl:

use Inline Java => <<'END',
  class JAxH {
    public JAxH(String x){
       System.out.println("Just Another " + x + " Hacker") ;
    }
  }
END

new JAxH('Inline') ;
There are other systems for making Perl and Java interact. You could always use CORBA (e.g., CORBA::MICO) or JPL (intro here). But the simplicity of the Inline system is very impressive. No messy business declaring types or messing with IDLs. Just run your Perl program and go!

It's been a long time coming. The origins of Perl are as a glue language, bringing together ("integrating" is the now-fashionable way to say that) various parts of a solution. Perl was a perfect solution to many problems back when the parts were programs. But if you wanted to access components as we know them now--variables and subroutines from libraries written in C, C++, or any other non-Perl language--you had to learn a lot about the innards of Perl to build an interface.

Inline changes that. This innovative module by Brian Ingerson takes the hassle out of talking to other programming languages. Inline::Java, by Patrick LeBoutillier, is the interface to Java, but there are others for Tcl, Python, C++, and assembly language.

Much kudos to Inline for truly making a hard thing easy.

Nat Torkington is conference planner for the Open Source Convention, OSCON Europe, and other O'Reilly conferences. He was project manager for Perl 6, is on the board of The Perl Foundation, and is a frequent speaker on open source topics. He cowrote the bestselling Perl Cookbook.

Return to weblogs.oreilly.com.



Weblog authors are solely responsible for the content and accuracy of their weblogs, including opinions they express, and O'Reilly Media, Inc., disclaims any and all liabililty for that content, its accuracy, and opinions it may contain.

Creative Commons License This work is licensed under a Creative Commons License.