尝试使用JAVA启动Pig脚本时出错

时间:2013-05-23 08:53:31

标签: java hadoop bigdata apache-pig

我正试图从JAVA发起一个猪脚本。这是我的代码:

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 pigCV {


public static void main(String args[]){

    PigServer pigServer;
    try {

        Properties props = new Properties();
        props.setProperty("fs.default.name", "hdfs://hdfs://localhost:8022");
        props.setProperty("mapred.job.tracker", "localhost:8021");

        pigServer = new PigServer(ExecType.MAPREDUCE, props);

        pigServer.registerScript("Desktop/text_v3.pig");

    } 
    catch (ExecException e) {   e.printStackTrace(); } 
    catch (IOException e) { e.printStackTrace(); }

}


}

但是抛出了一些例外:

  

2013-05-23 01:34:54,666 ERROR [main] conf.Configuration(1151):设置失败   解析器的setXIncludeAware(true)org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@1787038:java.lang.UnsupportedOperationException:此解析器不支持规范“null”版本“null”       java.lang.UnsupportedOperationException:此解析器不支持规范“null”版本“null”       在javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(DocumentBuilderFactory.java:590)       在org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:1149)       在org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:1125)       在org.apache.hadoop.conf.Configuration.getProps(Configuration.java:1064)       在org.apache.hadoop.conf.Configuration.get(Configuration.java:424)       在org.apache.hadoop.mapred.JobConf.checkAndWarnDeprecation(JobConf.java:1709)       在org.apache.hadoop.mapred.JobConf。(JobConf.java:164)       在org.apache.pig.backend.hadoop.executionengine.HExecutionEngine.init(HExecutionEngine.java:169)       在org.apache.pig.backend.hadoop.executionengine.HExecutionEngine.init(HExecutionEngine.java:137)       在org.apache.pig.impl.PigContext.connect(PigContext.java:200)       在org.apache.pig.PigServer。(PigServer.java:169)       在org.apache.pig.PigServer。(PigServer.java:158)       在org.apache.pig.PigServer。(PigServer.java:154)       在pigCV.main(pigCV.java:21)

你有什么想法帮助我吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

您的类路径中可能有(n旧)Xerces实现。 尝试设置

-Djavax.xml.parsers.DocumentBuilderFactory=
   com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

(在Eclipse中:VM参数)或代码中:

System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
  "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

注:
fs.default.name中可能存在拼写错误:不应该是hdfs://localhost:8022而不是hdfs://hdfs://localhost:8022吗?