.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Inline::Java 3" .TH Inline::Java 3 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Inline::Java \- Write Perl classes in Java. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 4 \& use Inline Java => <<\*(AqEND_OF_JAVA_CODE\*(Aq ; \& class Pod_alu { \& public Pod_alu(){ \& } \& \& public int add(int i, int j){ \& return i + j ; \& } \& \& public int subtract(int i, int j){ \& return i \- j ; \& } \& } \& END_OF_JAVA_CODE \& \& my $alu = new Pod_alu() ; \& print($alu\->add(9, 16) . "\en") ; # prints 25 \& print($alu\->subtract(9, 16) . "\en") ; # prints \-7 .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The \f(CW\*(C`Inline::Java\*(C'\fR module allows you to put Java source code directly "inline" in a Perl script or module. A Java compiler is launched and the Java code is compiled. Then Perl asks the Java classes what public methods have been defined. These classes and methods are available to the Perl program as if they had been written in Perl. .PP The process of interrogating the Java classes for public methods occurs the first time you run your Java code. The namespace is cached, and subsequent calls use the cached version. .SH "JDK COMPATIBILITY" .IX Header "JDK COMPATIBILITY" As of version 0.62, the minimum JDK supported is JDK 7. This is due to the "diamond operator" \f(CW\*(C`<>\*(C'\fR used for generic \f(CW\*(C`ArrayList\*(C'\fRs among others. .SH "USING THE Inline::Java MODULE" .IX Header "USING THE Inline::Java MODULE" \&\f(CW\*(C`Inline::Java\*(C'\fR is driven by fundamentally the same idea as other \&\f(CW\*(C`Inline\*(C'\fR language modules, like \f(CW\*(C`Inline::C\*(C'\fR or \f(CW\*(C`Inline::CPP\*(C'\fR. Because Java is both compiled and interpreted, the method of getting your code is different, but overall, using \f(CW\*(C`Inline::Java\*(C'\fR is very similar to any other \f(CW\*(C`Inline\*(C'\fR language module. .PP This section will explain the different ways to \f(CW\*(C`use\*(C'\fR Inline::Java. For more details on \f(CW\*(C`Inline\*(C'\fR, see 'perldoc Inline'. .PP \&\fBBasic Usage\fR .PP The most basic form for using \f(CW\*(C`Inline::Java\*(C'\fR is: .PP .Vb 1 \& use Inline Java => \*(AqJava source code\*(Aq ; .Ve .PP Of course, you can use Perl's "here document" style of quoting to make the code slightly easier to read: .PP .Vb 1 \& use Inline Java => <<\*(AqEND\*(Aq; \& \& Java source code goes here. \& \& END .Ve .PP The source code can also be specified as a filename, a subroutine reference (the subroutine should return source code), or an array reference (the array contains lines of source code). This information is detailed in 'perldoc Inline'. .PP In order for \f(CW\*(C`Inline::Java\*(C'\fR to function properly, it needs to know where to find a Java 2 SDK on your machine. This is done using one of the following techniques: .IP 1. 4 Set the J2SDK configuration option to the correct directory .IP 2. 4 Set the PERL_INLINE_JAVA_J2SDK environment variable to the correct directory .PP If none of these are specified, \f(CW\*(C`Inline::Java\*(C'\fR will use the Java 2 SDK that was specified at install time (see below). .SH "DEFAULT JAVA 2 SDK" .IX Header "DEFAULT JAVA 2 SDK" When \f(CW\*(C`Inline::Java\*(C'\fR was installed, the path to the Java 2 SDK that was used was stored in a file called default_j2sdk.pl that resides within the \f(CW\*(C`Inline::Java\*(C'\fR module. You can obtain this path by using the following command: .PP .Vb 1 \& % perl \-MInline::Java=j2sdk .Ve .PP If you wish to permanently change the default Java 2 SDK that is used by \f(CW\*(C`Inline::Java\*(C'\fR, edit this file and change the value found there. If you wish use a different Java 2 SDK temporarily, see the J2SDK configuration option described below. .PP Additionally, you can use the following command to get the list of directories that you should put in you shared library path when using the JNI extension: .PP .Vb 1 \& % perl \-MInline::Java=so_dirs .Ve .SH "CONFIGURATION OPTIONS" .IX Header "CONFIGURATION OPTIONS" There are a number of configuration options that dictate the behavior of \f(CW\*(C`Inline::Java\*(C'\fR: .IP j2sdk 4 .IX Item "j2sdk" Specifies the path to your Java 2 SDK. .Sp .Vb 1 \& Ex: j2sdk => \*(Aq/my/java/2/sdk/path\*(Aq .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP port 4 .IX Item "port" Specifies the port number for the server. Default is \-1 (next available port number), default for SHARED_JVM mode is 7891. .Sp .Vb 1 \& Ex: port => 4567 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP host 4 .IX Item "host" Specifies the host on which the JVM server is running. This option really only makes sense in SHARED_JVM mode when START_JVM is disabled. .Sp .Vb 1 \& Ex: host => \*(Aqjvm.server.com\*(Aq .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP bind 4 .IX Item "bind" Specifies the IP address on which the JVM server will be listening. By default the JVM server listens for connections on 'localhost' only. .Sp .Vb 2 \& Ex: bind => \*(Aq192.168.1.1\*(Aq \& Ex: bind => \*(Aq0.0.0.0\*(Aq .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP startup_delay 4 .IX Item "startup_delay" Specifies the maximum number of seconds that the Perl script will try to connect to the Java server. In other words this is the delay that Perl gives to the Java server to start. Default is 15 seconds. .Sp .Vb 1 \& Ex: startup_delay => 20 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP classpath 4 .IX Item "classpath" Adds the specified CLASSPATH. This CLASSPATH will only be available through the user classloader. To set the CLASSPATH globally (which is most probably what you want to do anyways), use the CLASSPATH environment variable. .Sp .Vb 1 \& Ex: classpath => \*(Aq/my/other/java/classses\*(Aq .Ve .IP jni 4 .IX Item "jni" Toggles the execution mode. The default is to use the client/server mode. To use the JNI extension (you must have built it at install time though; see README and README.JNI for more information), set JNI to 1. .Sp .Vb 1 \& Ex: jni => 1 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP "extra_java_args, extra_javac_args" 4 .IX Item "extra_java_args, extra_javac_args" Specify extra command line parameters to be passed to, respectively, the JVM and the Java compiler. Use with caution as some options may alter normal \f(CW\*(C`Inline::Java\*(C'\fR behavior. .Sp .Vb 1 \& Ex: extra_java_args => \*(Aq\-Xmx96m\*(Aq .Ve .Sp Note: extra_java_args only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP embedded_jni 4 .IX Item "embedded_jni" Same as jni, except \f(CW\*(C`Inline::Java\*(C'\fR expects the JVM to already be loaded and to have loaded the Perl interpreter that is running the script. This is an advanced feature that should only be need in very specific circumstances. .Sp .Vb 1 \& Ex: embedded_jni => 1 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. Also, the embedded_jni option automatically sets the JNI option. .IP shared_jvm 4 .IX Item "shared_jvm" This mode enables multiple processes to share the same JVM. It was created mainly in order to be able to use \f(CW\*(C`Inline::Java\*(C'\fR under mod_perl. .Sp .Vb 1 \& Ex: shared_jvm => 1 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP start_jvm 4 .IX Item "start_jvm" When used with shared_jvm, tells \f(CW\*(C`Inline::Java\*(C'\fR whether to start a new JVM (this is the default) or to expect that one is already running. This option is useful in combination with the command line interface described in the BUGS AND DEFICIENCIES section. Default is 1. .Sp .Vb 1 \& Ex: start_jvm => 0 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP private 4 .IX Item "private" In shared_jvm mode, makes every connection to the JVM use a different classloader so that each connection is isolated from the others. .Sp .Vb 1 \& Ex: private => 1 .Ve .Sp Note: This configuration option only has an effect on the first \&'use Inline Java' call inside a Perl script, since all other calls make use of the same JVM. .IP debug 4 .IX Item "debug" Enables debugging info. Debugging now uses levels (1 through 5) that (loosely) follow these definitions: .Sp .Vb 5 \& 1 = Major program steps \& 2 = Object creation/destruction \& 3 = Method/member accesses + packet dumps \& 4 = Everything else \& 5 = Data structure dumps \& \& Ex: debug => 2 .Ve .IP debugger 4 .IX Item "debugger" Starts jdb (the Java debugger) instead of the regular Java JVM. This option will also cause the Java code to be compiled using the \&'\-g' switch for extra debugging information. EXTRA_JAVA_ARGS can be used use to pass extra options to the debugger. .Sp .Vb 1 \& Ex: debugger => 1 .Ve .IP warn_method_select 4 .IX Item "warn_method_select" Throws a warning when \f(CW\*(C`Inline::Java\*(C'\fR has to 'choose' between different method signatures. The warning states the possible choices and the signature chosen. .Sp .Vb 1 \& Ex: warn_method_select => 1 .Ve .IP study 4 .IX Item "study" Takes an array of Java classes that you wish to have \&\f(CW\*(C`Inline::Java\*(C'\fR learn about so that you can use them inside Perl. .Sp .Vb 1 \& Ex: study => [\*(Aqjava.lang.HashMap\*(Aq, \*(Aqmy.class\*(Aq] .Ve .IP autostudy 4 .IX Item "autostudy" Makes \f(CW\*(C`Inline::Java\*(C'\fR automatically study unknown classes when it encounters them. .Sp .Vb 1 \& Ex: autostudy => 1 .Ve .IP package 4 .IX Item "package" Forces \f(CW\*(C`Inline::Java\*(C'\fR to bind the Java code under the specified package instead of under the current (caller) package. .Sp .Vb 1 \& Ex: package => \*(Aqmain\*(Aq .Ve .IP native_doubles 4 .IX Item "native_doubles" Normally, \f(CW\*(C`Inline::Java\*(C'\fR stringifies floating point numbers when passing them between Perl and Java. In certain cases, this can lead to loss of precision. When native_doubles is set, \f(CW\*(C`Inline::Java\*(C'\fR will send the actual double bytes in order to preserve precision. Note: This applies only to doubles, not floats. Note: This option may not be portable and may not work properly on some platforms. .Sp .Vb 1 \& Ex: native_doubles => 1 .Ve .SH "ENVIRONMENT VARIABLES" .IX Header "ENVIRONMENT VARIABLES" Every configuration option listed above, with the exception of STUDY, can be specified using an environment variable named using the following convention: .PP .Vb 1 \& PERL_INLINE_JAVA_