我想提供一个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”,非常想你!
1条答案
按热度按时间velaa5lx1#
我发现原因是我没有在tomcat中设置环境变量。只需在server/bin/start.sh中添加以下内容