Link to home
Start Free TrialLog in
Avatar of texasreddog
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/RunSystemCommand';

my $command =  $ENV{'JAVA_HOME'}
               . ( $ENV{'JAVA_HOME'} =~ m#/$# ? '' : '/' )
               . 'bin/java -classpath "/nethome/gerdesk/scripts/java" '
               . +JAVA_CLASS . ' ';

my $file = '/nethome/gerdesk/scripts/logs/javawrapper.log';

print "Java command = $command\n";

open( EXPORTER, "|$command 2>$file" ) or die "Cannot start java command: $!";
#while (defined( my $output = <EXPORTER> )) {
#  $broker->getUI()->traceInfo( $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/java/RunSystemCommand
Exit status 256 from java command at javawrapper.pl line 19.
Unable to run java command: Exception in thread "main" java.lang.NoClassDefFoundError: /nethome/gerdesk/scripts/java/RunSystemCommand

How do I set the classpath correctly in the Perl wrapper script before the java command is called?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)