无法使用java命令运行Pig jar

时间:2015-12-02 13:17:33

标签: java linux hadoop apache-pig

我正在尝试简单的猪代码,但它给了我一些许可。 这是我的示例猪代码

import java.io.IOException;
import org.apache.pig.PigServer;
import org.apache.pig.ExecType;
import org.apache.hadoop.conf.Configuration;
public class PigTest{
   public static void main(String[] args) {
   try {
        Configuration conf = new Configuration();
        conf.set("hdp.version","2.3.0.0-2557");
        //PigServer pigServer = new PigServer("mapreduce",conf);
        PigServer pigServer = new PigServer(ExecType.MAPREDUCE, conf);
     runIdQuery(pigServer, "myfile.txt");
   }
   catch(Exception e) {
   }
}
public static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {
   pigServer.registerQuery("A = load '" + inputFile + "' using PigStorage(':');");
   pigServer.registerQuery("B = foreach A generate $0 as id;");
   pigServer.store("B", "idout");
   }
}

我将classpath设置如下

echo $CLASSPATH
.:/usr/hdp/2.3.0.0-2557/hadoop/client/*:/usr/hdp/2.3.0.0-2557/hadoop-hdfs/lib/*:/usr/hdp/2.3.0.0-2557/hadoop-mapreduce/lib/*:/usr/hdp/2.3.0.0-2557/hadoop-yarn/lib/*:/usr/hdp/2.3.0.0-2557/pig/lib/*:/usr/hdp/2.3.0.0-2557/hadoop/conf:/usr/hdp/2.3.0.0-2557/pig/pig-0.15.0.2.3.0.0-2557-core-h2.jar

当我使用java命令运行我的代码时,它运行正常但是当我创建了一个代码并尝试运行时,它给了我以下权限错误。

 ****java -cp /usr/hdp/2.3.0.0-2557/hadoop/client/*;/usr/hdp/2.3.0.0-2557/hadoop-hdfs/lib/*;/usr/hdp/2.3.0.0-2557/hadoop-mapreduce/lib/*;/usr/hdp/2.3.0.0-2557/hadoop-yarn/lib/*;/usr/hdp/2.3.0.0-2557/pig/lib/*;/usr/hdp/2.3.0.0-2557/hadoop/conf;/usr/hdp/2.3.0.0-2557/pig/pig-0.15.0.2.3.0.0-2557-core-h2.jar -jar PigTest.jar****


Error: Could not find or load main class .usr.hdp.2.3.0.0-2557.hadoop.client.activation.jar
-bash: /usr/hdp/2.3.0.0-2557/hadoop-hdfs/lib/asm-3.2.jar: Permission denied
-bash: /usr/hdp/2.3.0.0-2557/hadoop-mapreduce/lib/aopalliance-1.0.jar: Permission denied
-bash: /usr/hdp/2.3.0.0-2557/hadoop-yarn/lib/activation-1.1.jar: Permission denied
-bash: /usr/hdp/2.3.0.0-2557/pig/lib/accumulo-core-1.5.0.jar: Permission denied
-bash: /usr/hdp/2.3.0.0-2557/hadoop/conf: is a directory
-bash: /usr/hdp/2.3.0.0-2557/pig/pig-0.15.0.2.3.0.0-2557-core-h2.jar: Permission denied

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试以下

  1. 而不是/usr/hdp/2.3.0.0-2557/hadoop/client/*使用/usr/hdp/2.3.0.0-2557/hadoop/client/*.jar(请参见最后的.jar。将所有*替换为* .jar)
  2. 使用冒号(:)代替分号(;)。冒号用于在Linux上分隔路径
  3. 如果上面的第1步不起作用,请尝试将单个JAR放入路径而不是* .jar