• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1486
  • Last Modified:

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?
0
texasreddog
Asked:
texasreddog
  • 2
2 Solutions
 
objectsCommented:


try:

/usr/local/java/bin/java -classpath "/nethome/gerdesk/scripts/java"  RunSystemCommand
0
 
CEHJCommented:
You would of course do that by changing your constant to

use constant JAVA_CLASS => 'RunSystemCommand';
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now