CleanCode Perl Libraries
Multi-Lingual Library Maintainability
available: Perl not available: Java not available: JavaScript not available: Certified
Class
not available: Testable
Class
not available: Standalone
Mode
available: Diagnostic
Enabled

NAME

Proc::ExecJava - Executes a Java program.

SYNOPSIS

        use Proc::ExecJava;
        $javaProg=Proc::ExecJava->new(
                $JAVA_BIN_PATH,$JAVA_CLASS_PATH,"com.cleancode.net.URLReader");
        $javaProg->setSystemProperties("verbose");
        $javaStatus = $javaProg->run($url, $cookie);
        return ($javaStatus? "java error" : $javaProg->output());

REQUIRES

Perl5.005

DESCRIPTION

This module allows you to run a Java program specifying (1) the path to your Java binary; (2) the path to your Java class library; (3) the class to execute; (4) any system properties; and (5) parameters to pass on the command line to the class.

You specify the first three in the object constructor. System properties, if needed, may be specified via the setSystemProperties method, Each of these will appear between the java interpreter and the class, as in

        java -Dprop1 -Dprop2=foobar -Dprop3 class_to_run

Note that you should not include the -D itself.

You may then run the Java program one or multiple times via the run method, varying the properties, if desired, and the command-line arguments. The command-line arguments are passed directly to the run method. If the run method returns a status of 0, then you can obtain the output of the run via the output method.

CLASS VARIABLES

$VERSION

Current version of this class.

CONSTRUCTOR

new

PACKAGE->new(binPath, classPath, className)

Creates a Java object with which to execute a Java program.

Parameters:

binPath - optional; string; path to the Java executable. If not specified, your default search path will be used.

classPath - optional; string; java class path. This contains a list of directories to search for required classes, separated by semicolons. If not specified, your default CLASSPATH environment setting will be used.

className - string; java class name to execute.

Returns:

a newly created object

METHODS

setSystemProperties

OBJ->setSystemProperties(arg,...)

Specifies a list of system properties to pass to the Java interpreter. Any previous system properties will be deleted. Hence, to ensure no leftover properties from previous invocations during the lifetime of the enclosing Perl program invoke setSystemProperties with no arguments.

Parameters:

arg - optional; string; system property of the form name or name=value.

run

OBJ->run(arg,...)

Executes the Java program defined by the constructor with the list of system properties from setSystemProperties, and the list of args specified here.

Parameters:

arg - optional; string; command-line argument to pass to the Java program.

Returns:

Java program status (0 indicates normal termination).

output

OBJ->output()

Returns the output of the Java program.

Returns:

Output of the Java program. The output is returned as a list or as a string, depending on context of the caller.

BUGS

None

AUTHOR

Michael Sorens

VERSION

$Revision: 8 $ $Date: 2006-12-19 21:13:43 -0800 (Tue, 19 Dec 2006) $

SINCE

CleanCode 0.9

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 104:

=back doesn't take any parameters, but you said =back -- end of CLASS VARIABLES section

Around line 140:

=back doesn't take any parameters, but you said =back -- end of CONSTRUCTOR section

Around line 253:

=back doesn't take any parameters, but you said =back -- end of METHOD section


CleanCode Perl Libraries Copyright © 2001-2013 Michael Sorens - Revised 2013.06.30 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads