简体   繁体   中英

Unable to run Pig jar using java command

I am trying to simple pig code but its giving me some permission. Here is my sample pig code

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");
   }
}

I set my classpath as below

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

When i am running my code with java command it is working perfectly but when created a jar of my code and trying to run , it is giving me below permission error.

 ****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

How do i fix this?

Try the following

  1. Instead of /usr/hdp/2.3.0.0-2557/hadoop/client/* use /usr/hdp/2.3.0.0-2557/hadoop/client/*.jar (See .jar at the end. Replace all * with *.jar)
  2. Instead of semi-colon ( ; ) try with colon ( : ). Colon is used to separate path on Linux
  3. If step 1 above does not work then try putting individual JAR in the path instead of *.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM