2015-06-21 109 views
0

我在Eclipse(tomcat8 localhost)中使用JAX-WS,我需要从中调用Perl脚本。使用下面的代码,我能够达到Match.pl的前三行。但是,当它达到use Stats;时,过程返回退出值2.无法从Java代码调用Perl脚本

Stats.pm文件与Match.pl文件位于同一目录中,该文件已通过hello.sh脚本导出到PERL5LIB。

我在做什么错?有没有办法使用相对路径而不是绝对路径?

@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 
+0

是perl在你的路径吗?有什么异常? –

+0

是的,perl在路径中(并且部分为Match.pl运行)。我看不到任何来自Eclipse的异常 – Arturo

+0

我的猜测是在运行perl脚本之前没有完成导出 – Arturo

回答

2

尝试增加:

use FindBin; 
use lib $FindBin::RealBin; 

这将添加脚本是到库搜索路径的目录。

编辑:shell脚本不起作用,因为它改变了shell进程的环境,而不是产生它的Java进程。