tomcat::permission deny中的java调用配置单元

x6yk4ghg  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(278)

我想提供一个hiveclient.jar来执行配置单元sql。代码如下

public class HiveClient {
    private String sql;

    public HiveClient(String sql) {
        this.sql = sql; 
    }

    public int procedure(){
        String[] command = {"hive", "-e", sql};
        Process process = Runtime.getRuntime().exec(command);
        ...
        do something with process...
    }

}
我将输入sql并从process.getinputstream()获取输出。
问题是,当我在linux shell中调用这个jar时,一切正常

java -cp .:./hiveClient.jar HiveMain

但是当我把这个jar放在tomcat lib文件夹中,并调用这个对象时,会出现permission deny错误。但是,hive用户和tomcat用户都是“admin”。

HiveClient hc = new HiveClient(parameters.toString());
int returnCode = hc.procedure();

java.io.IOException: Cannot run program "hive": error=13, permission deny
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:485)
at com.jd.ads.data.hiveClient.HiveClient.execute(HiveClient.java:89)
at com.jd.ads.data.hiveClient.HiveClient.procedure(HiveClient.java:146)
at com.jd.ad.data.download.handler.InvokeHiveHandler.read(InvokeHiveHandler.java:78)
at com.jd.ad.data.download.handler.AbstractRunableHandler.run(AbstractRunableHandler.java:61)
at com.jd.ad.data.download.pipeline.DefaultPipeLine.run(DefaultPipeLine.java:103)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: error=13, permission deny
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 10 more

我想知道我怎么能在tomcat里叫“Hive-e”,非常想你!

velaa5lx

velaa5lx1#

我发现原因是我没有在tomcat中设置环境变量。只需在server/bin/start.sh中添加以下内容

export PATH=/export/jdhive-2.0.0-HADOOP-2.7.1/bin:/export/hadoop-2.7.1-admin/bin:/export/hadoop-2.7.1-admin/sbin:/export/hadoop-2.7.1-admin/jdk1.7.0_67/bin:/export/servers/jdk1.7.0_71/bin:$PATH
export HIVE_HOME=/export/jdhive-2.0.0-HADOOP-2.7.1
export UDF_PATH=$HIVE_HOME/udf

相关问题