PBJ::JNI - Full access to and from Java virtual machine from Perl.
use PBJ::JNI::JavaVM; my ($env, $jvm, @vm_opts); my ($cls, $fid, $mid, $out); # Create the Java VM @vm_opts = ("-Xrs", "-Xcheck:jni"); $jvm = new PBJ::JNI::JavaVM(); $env = $jvm->get_env(@vm_opts); $env->PushLocalFrame(16) == 0 or die; $cls = $env->FindClass("java/lang/System") or die; $fid = $env->GetStaticFieldID($cls, "out", "Ljava/io/PrintStream;") or die; $out = $env->GetStaticObjectField($cls, $fid) or die; $cls = $env->GetObjectClass($out) or die; $mid = $env->GetMethodID($cls, "println", "(I)V") or die; $env->CallVoidMethod($out, $mid, $env->cast("I", 12345)); $env->PopLocalFrame(0);
This software is still in alpha stage. It may not be reliable and its features and APIs may change in the future releases.
PBJ::JNI package allows you to link with your Java virtual machine and directly access Java classes from Perl. It also allows a mechanism to create callbacks from Java program to Perl subroutines.
The package focuses on providing a set of APIs that closely resemble the native JNI interface. This basically means that you can write an ordinary JNI program in Perl instead of in C or C++. This provides a quicker way to writing wrappers to invoke programs written in Java and therefore introduce Java libraries to the Perl without the trouble of writing low level C/C++ programs.
You will need to know how JNI works in order to use this package. This package is by definition very primitive. If you don't understand thoroughly on how JNI works and try to use the feature of this package, you can easily crash your program or create memory leaks. So don't do that.
It is my hope that somebody with proper skills in JNI and Perl can write wrappers for a set of popular Java libraries, such as JDBC, XML parser, JMS (that I am working on), and other useful Java packages so that a Perl programmer can use them directly in a pure Perl environment without knowing anything about JNI.
Please refer to the test programs in the "t" directory of the distribution for some simple examples.
Among the known limitations in this package:
- PBJ::JNI::JavaVM - PBJ::JNI::JNIEnv - PBJ::JNI::Util - PBJ::JNI::Native
Ping Liang, <email@example.com>
Copyright (c) 2001 Ping Liang All rights reserved.
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
This program is licensed under the same terms as Perl itself. For more information see the README or Artistic files provided with the Perl distribution.