0

I am using JAX-WS in Eclipse (tomcat8 localhost) and I need to call a Perl script from it. Using the code below, I am able to reach the first three lines of Match.pl. However, when it reaches use Stats;, the process returns exitvalue 2.

The Stats.pm file is in the same directory as Match.pl, which has been exported to PERL5LIB with hello.sh script.

What am I doing wrong? Is there a way to use relative paths instead of absolute ones?

@Path("/")
public class MyService {
    @POST
    @Path("/generatePath")
    @Produces(MediaType.TEXT_PLAIN)
    public Response generatePathService(
            @FormParam("url") String fileURL) throws IOException, InterruptedException {
        Process p0 = Runtime.getRuntime().exec("sh /home/me/workspace/MyService/hello.sh");
        p0.waitFor();
        Process p = Runtime.getRuntime().exec("perl /home/me/workspace/MyService/Match.pl");
        p.waitFor();

        return Response.status(200).entity(fileURL).build();
    }
}

Match.pl

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
use Stats;

Stats.pm

#!/usr/bin/perl

package Stats;

use strict;
use warnings;

hello.sh

#!/bin/bash

export PERL5LIB=/home/me/workspace/MyService
6
  • is perl in your path? Any exception? Commented Jun 21, 2015 at 23:40
  • Yes, perl is in the path (and partially runs for Match.pl). I cannot see any exceptions from Eclipse Commented Jun 21, 2015 at 23:48
  • My guess is that the export is not completed before the perl script is run Commented Jun 21, 2015 at 23:54
  • 1
    export works in the same shell, and as you are launching two different process so i don't think export will be available for the second one. Try combining both the scripts and check the result. Commented Jun 21, 2015 at 23:57
  • 1
    Call Match.pl from hello.sh Commented Jun 22, 2015 at 0:16

1 Answer 1

1

Try adding:

use FindBin;
use lib $FindBin::RealBin;

This will add the directory that the script is in to the library search path.

Edit: The shell script is not working because it changes the environment of the shell process, not the Java process that spawned it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.