Inline Java In Perl

A former perl guru colleague of mine showed me Inline::Java, a way to embed Java in your perl programs and call perl from your Java classes.

The way it works is it invokes javac and creates some bytecode.  It then runs its own perl mapper (reflecting on said bytecode) so that the Perl code can use the Java public methods and attributes.

If you reference a java package outside the scope of your code (eg java.util or your own packages in a separate jar), then this module will also reflect those too.  You can specify a CLASSPATH environment variable so it knows where to look for these jars.

According to the bugs db there weren’t too many though how active the project still is remains to be seen.  Apparently the implementation can be a bit slow but there is a JNI option to speed things up.  I also suspect there is some problem with more unique java properties, apparently the module balks when it tries to see the Oracle 10 JDBC driver jar because of a public synchronized property.

Regardless if you’ve got Perl code that you want to migrate to Java, this would be a nice first step to bridge the gap.

See these sub modules for more info on how you can bridge the gap from the Java side

Inline::Java::Callback, Inline::Java::PerlNatives, Inline::Java::PerlInterpreter

Based on this, the equally cool, Java::Swing project emerged which leverages on the above.

Leave a Reply