Pig Error: Could not find or load main class org.apache.pig.Main
Pig Error: Could not find or load main class org.apache.pig.Main
我是 PIG 的初学者。
我按照 WIKI 编写了一个程序,将文件中的单词转换为大写。
--猫UPPER.java
package com.bigdata.myUdf;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;
public class UPPER extends EvalFunc<String> {
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
try{
String str = (String)input.get(0);
return str.toUpperCase();
}catch(Exception e){
throw WrappedIOException.wrap("Caught exception processing input row ", e);
}
}
}
-- 猫/home/hduser/lab/mydata/myscript.猪
REGISTER /home/hduser/software/myUdfs/UPPER.jar
std_det = LOAD '/pigdata/udf1.txt' USING PigStorage(',') as (name:chararray);
B = FOREACH std_det GENERATE com.bigdata.myUdf.UPPER(name);
dump B;
但是当我运行它时出现错误。
java -cp com.bigdata.myUdf.UPPER.jar org.apache.pig.Main -x local /home/hduser/lab/mydata/myscript.pig
错误
Error: Could not find or load main class org.apache.pig.Main
猫.bashrc
export PIG_INSTALL=/home/hduser/software/pig
export PATH="${PATH}:${PIG_INSTALL}/bin"
export PIG_CLASSPATH=$HADOOP_CONF_DIR:${PIG_INSTALL}:.
export CLASSPATH=.:${PIG_CLASSPATH}
猪脚本位于:
/home/hduser/lab/mydata/myscript.猪
JAR 文件位于:
/home/hduser/software/myUdfs/UPPER.jar
请帮助我理解我做错了什么。提前致谢。
在遵循 Shivashakti 的指示后。程序运行但没有给出任何输出。
pig -x local myScript.pig
15/01/05 04:47:57 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
15/01/05 04:47:57 INFO pig.ExecTypeProvider: Picked LOCAL as the ExecType
2015-01-05 04:47:57,920 [main] INFO org.apache.pig.Main - Apache Pig version 0.14.0 (r1640057) compiled Nov 16 2014, 18:02:05
2015-01-05 04:47:57,921 [main] INFO org.apache.pig.Main - Logging error messages to: /home/hduser/lab/piglog/pig_1420462077918.log
2015-01-05 04:47:57,959 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - user.name is deprecated. Instead, use mapreduce.job.user.name
2015-01-05 04:47:58,314 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:58,315 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
2015-01-05 04:47:58,318 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: file:///
2015-01-05 04:47:58,463 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:59,070 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:59,227 [main] INFO org.apache.pig.Main - Pig script completed in 2 seconds and 505 milliseconds (2505 ms)
该错误表明 apache jar 不在类路径中。 -cp com.bigdata.myUdf.UPPER.jar
不包括所需的罐子。它只包括 'UPPER.jar'。您可以看看如何在类路径 here
中正确包含所有必需的 jar
P.S。我认为您应该从命令行使用 pig 命令,而不是按照您的方式执行。但是我自己没用过所以只是猜测。
您可以按照以下步骤操作吗?
1.Download 下面的 3 个 jar 文件 link(pig-0.11.1.jar,hadoop-common-0.21.0.jar 和 piggybank.jar)
http://www.java2s.com/Code/Jar/p/Downloadpig0111jar.htm
http://www.java2s.com/Code/Jar/h/Downloadhadoopcommon0210jar.htm
http://www.java2s.com/Code/Jar/p/Downloadpiggybankjar.htm
2。将以上 3 个 jar 文件全部设置到你的类路径
export CLASSPATH=/tmp/pig-0.11.1.jar:/tmp/hadoop-common-0.21.0.jar:/tmp/piggybank.jar
3。从当前目录
创建目录名称"com/bigdata/myUdf/"
>>mkdir -p com/bigdata/myUdf/
4。编译 UPPER.java 文件并确保 JAVA_HOME 设置正确,并且上述三个 jar 文件都包含在类路径中,否则会出现编译问题
>>javac UPPER.java
5.将编译好的UPPER.class文件移动到"com/bigdata/myUdf/"文件夹
>>mv UPPER.class com/bigdata/myUdf/
6.创建一个jar文件名UPPER.jar
>>jar -cvf UPPER.jar com/
7.现在将 UPPER.jar 包含到您的 pig 脚本中,并 运行 下面的命令
>>pig -x local myscript.pig
一旦你运行上面的命令你就会得到实际的输出。
例子
输入
hello
world
myscript.pig
REGISTER UPPER.jar;
std_det = LOAD 'input' USING PigStorage(',') as (name:chararray);
B = FOREACH std_det GENERATE com.bigdata.myUdf.UPPER(name);
dump B;
输出:
(HELLO)
(WORLD)
示例命令:
$ ls
UPPER.java input myscript.pig
$ mkdir -p com/bigdata/myUdf/
$ javac UPPER.java
$ mv UPPER.class com/bigdata/myUdf/
$ jar -cvf UPPER.jar com/
$ pig -x local myscript.pig
我是 PIG 的初学者。
我按照 WIKI 编写了一个程序,将文件中的单词转换为大写。
--猫UPPER.java
package com.bigdata.myUdf;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;
public class UPPER extends EvalFunc<String> {
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
try{
String str = (String)input.get(0);
return str.toUpperCase();
}catch(Exception e){
throw WrappedIOException.wrap("Caught exception processing input row ", e);
}
}
}
-- 猫/home/hduser/lab/mydata/myscript.猪
REGISTER /home/hduser/software/myUdfs/UPPER.jar
std_det = LOAD '/pigdata/udf1.txt' USING PigStorage(',') as (name:chararray);
B = FOREACH std_det GENERATE com.bigdata.myUdf.UPPER(name);
dump B;
但是当我运行它时出现错误。
java -cp com.bigdata.myUdf.UPPER.jar org.apache.pig.Main -x local /home/hduser/lab/mydata/myscript.pig
错误
Error: Could not find or load main class org.apache.pig.Main
猫.bashrc
export PIG_INSTALL=/home/hduser/software/pig
export PATH="${PATH}:${PIG_INSTALL}/bin"
export PIG_CLASSPATH=$HADOOP_CONF_DIR:${PIG_INSTALL}:.
export CLASSPATH=.:${PIG_CLASSPATH}
猪脚本位于: /home/hduser/lab/mydata/myscript.猪
JAR 文件位于: /home/hduser/software/myUdfs/UPPER.jar
请帮助我理解我做错了什么。提前致谢。 在遵循 Shivashakti 的指示后。程序运行但没有给出任何输出。
pig -x local myScript.pig
15/01/05 04:47:57 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
15/01/05 04:47:57 INFO pig.ExecTypeProvider: Picked LOCAL as the ExecType
2015-01-05 04:47:57,920 [main] INFO org.apache.pig.Main - Apache Pig version 0.14.0 (r1640057) compiled Nov 16 2014, 18:02:05
2015-01-05 04:47:57,921 [main] INFO org.apache.pig.Main - Logging error messages to: /home/hduser/lab/piglog/pig_1420462077918.log
2015-01-05 04:47:57,959 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - user.name is deprecated. Instead, use mapreduce.job.user.name
2015-01-05 04:47:58,314 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:58,315 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
2015-01-05 04:47:58,318 [main] INFO org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: file:///
2015-01-05 04:47:58,463 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:59,070 [main] INFO org.apache.hadoop.conf.Configuration.deprecation - fs.default.name is deprecated. Instead, use fs.defaultFS
2015-01-05 04:47:59,227 [main] INFO org.apache.pig.Main - Pig script completed in 2 seconds and 505 milliseconds (2505 ms)
该错误表明 apache jar 不在类路径中。 -cp com.bigdata.myUdf.UPPER.jar
不包括所需的罐子。它只包括 'UPPER.jar'。您可以看看如何在类路径 here
P.S。我认为您应该从命令行使用 pig 命令,而不是按照您的方式执行。但是我自己没用过所以只是猜测。
您可以按照以下步骤操作吗?
1.Download 下面的 3 个 jar 文件 link(pig-0.11.1.jar,hadoop-common-0.21.0.jar 和 piggybank.jar)
http://www.java2s.com/Code/Jar/p/Downloadpig0111jar.htm
http://www.java2s.com/Code/Jar/h/Downloadhadoopcommon0210jar.htm
http://www.java2s.com/Code/Jar/p/Downloadpiggybankjar.htm
2。将以上 3 个 jar 文件全部设置到你的类路径
export CLASSPATH=/tmp/pig-0.11.1.jar:/tmp/hadoop-common-0.21.0.jar:/tmp/piggybank.jar
3。从当前目录
创建目录名称"com/bigdata/myUdf/">>mkdir -p com/bigdata/myUdf/
4。编译 UPPER.java 文件并确保 JAVA_HOME 设置正确,并且上述三个 jar 文件都包含在类路径中,否则会出现编译问题
>>javac UPPER.java
5.将编译好的UPPER.class文件移动到"com/bigdata/myUdf/"文件夹
>>mv UPPER.class com/bigdata/myUdf/
6.创建一个jar文件名UPPER.jar
>>jar -cvf UPPER.jar com/
7.现在将 UPPER.jar 包含到您的 pig 脚本中,并 运行 下面的命令
>>pig -x local myscript.pig
一旦你运行上面的命令你就会得到实际的输出。
例子
输入
hello
world
myscript.pig
REGISTER UPPER.jar;
std_det = LOAD 'input' USING PigStorage(',') as (name:chararray);
B = FOREACH std_det GENERATE com.bigdata.myUdf.UPPER(name);
dump B;
输出:
(HELLO)
(WORLD)
示例命令:
$ ls
UPPER.java input myscript.pig
$ mkdir -p com/bigdata/myUdf/
$ javac UPPER.java
$ mv UPPER.class com/bigdata/myUdf/
$ jar -cvf UPPER.jar com/
$ pig -x local myscript.pig