texasreddog
asked on
correct way of setting java classpath in Perl script before java program is called
I have a Perl script that calls a Java program, but I am not setting the classpath correctly within Perl, and I need to do so to get this working. Here is my script:
#!/usr/bin/perl
use POSIX 'sys_wait_h', 'strftime';
use constant JAVA_CLASS => '/nethome/gerdesk/scripts/ java/RunSy stemComman d';
my $command = $ENV{'JAVA_HOME'}
. ( $ENV{'JAVA_HOME'} =~ m#/$# ? '' : '/' )
. 'bin/java -classpath "/nethome/gerdesk/scripts/ java" '
. +JAVA_CLASS . ' ';
my $file = '/nethome/gerdesk/scripts/ logs/javaw rapper.log ';
print "Java command = $command\n";
open( EXPORTER, "|$command 2>$file" ) or die "Cannot start java command: $!";
#while (defined( my $output = <EXPORTER> )) {
# $broker->getUI()->traceInf o( $output );
#}
close( EXPORTER ) or warn $! ? "Error closing java command pipe: $!"
: "Exit status $? from java command";
if (WEXITSTATUS($?)) {
open( ERRFILE, $file );
my $errors = join ("", <ERRFILE>);
die "Unable to run java command: $errors";
close( ERRFILE );
} else {
print "Java command $command executed successfully!\n";
}
The error I get is this, and I know it is because of the classpath:
Java command = /usr/local/java/bin/java -classpath "/nethome/gerdesk/scripts/ java" /nethome/gerdesk/scripts/j ava/RunSys temCommand
Exit status 256 from java command at javawrapper.pl line 19.
Unable to run java command: Exception in thread "main" java.lang.NoClassDefFoundE rror: /nethome/gerdesk/scripts/j ava/RunSys temCommand
How do I set the classpath correctly in the Perl wrapper script before the java command is called?
#!/usr/bin/perl
use POSIX 'sys_wait_h', 'strftime';
use constant JAVA_CLASS => '/nethome/gerdesk/scripts/
my $command = $ENV{'JAVA_HOME'}
. ( $ENV{'JAVA_HOME'} =~ m#/$# ? '' : '/' )
. 'bin/java -classpath "/nethome/gerdesk/scripts/
. +JAVA_CLASS . ' ';
my $file = '/nethome/gerdesk/scripts/
print "Java command = $command\n";
open( EXPORTER, "|$command 2>$file" ) or die "Cannot start java command: $!";
#while (defined( my $output = <EXPORTER> )) {
# $broker->getUI()->traceInf
#}
close( EXPORTER ) or warn $! ? "Error closing java command pipe: $!"
: "Exit status $? from java command";
if (WEXITSTATUS($?)) {
open( ERRFILE, $file );
my $errors = join ("", <ERRFILE>);
die "Unable to run java command: $errors";
close( ERRFILE );
} else {
print "Java command $command executed successfully!\n";
}
The error I get is this, and I know it is because of the classpath:
Java command = /usr/local/java/bin/java -classpath "/nethome/gerdesk/scripts/
Exit status 256 from java command at javawrapper.pl line 19.
Unable to run java command: Exception in thread "main" java.lang.NoClassDefFoundE
How do I set the classpath correctly in the Perl wrapper script before the java command is called?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)