在java中执行pigserver时出错

klr1opcd  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(411)

我正试图从我的java机器上远程运行pig脚本,为此我编写了以下代码
代码:

import java.io.IOException;
import java.util.Properties;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;

public class Javapig{ 
public static void main(String[] args) {
try {
    Properties props = new Properties();
    props.setProperty("fs.default.name", "hdfs://hdfs://192.168.x.xxx:8022");
    props.setProperty("mapred.job.tracker", "192.168.x.xxx:8021");

    PigServer pigServer = new PigServer(ExecType.MAPREDUCE, props);
    runIdQuery(pigServer, "fact");
    }
    catch(Exception e) {
        System.out.println(e);
    }
 }
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
    pigServer.registerQuery("A = load '" + inputFile + "' using org.apache.hive.hcatalog.pig.HCatLoader();");
    pigServer.registerQuery("B = FILTER A by category == 'Aller';");
    pigServer.registerQuery("DUMP B;");
    System.out.println("Done");
 }
}

但在执行时,我得到以下错误。
错误

ERROR 4010: Cannot find hadoop configurations in classpath (neither hadoop-site.xml nor core-site.xml was found in the classpath).

我不知道我做错了什么。

inkz8wg9

inkz8wg91#

自我描述的错误。。。
在类路径中找不到hadoop-site.xml或core-site.xml
在应用程序的类路径中需要这两个文件。
你最好能从你的 $HADOOP_CONF_DIR 文件夹,然后将它们复制到java的 src/main/resources ,假设你有一个maven结构
而且,对于这些文件,您应该使用 Configuration hadoop的对象

PigServer(ExecType execType, org.apache.hadoop.conf.Configuration conf)

相关问题