[英]Unable to run Pig Embbeded Java Program in Ubuntu
recently I do research on Apache Pig and I'm try to build Pig-Embedded Java Program. 最近,我对Apache Pig进行了研究,并尝试构建Pig-Embedded Java程序。 I found and copied an example from a website (From https://acadgild.com/blog/embedding-pig-java/ ) and I try to compile it before I run.
我从网站(从https://acadgild.com/blog/embedding-pig-java/ )找到并复制了一个示例,然后在运行之前尝试对其进行编译。
javac pig_java.java
The compilation is successful without prompt any error. 编译成功,没有提示任何错误。 However when I follow the instruction in https://wiki.apache.org/pig/EmbeddedPig and run the following command:
但是,当我按照https://wiki.apache.org/pig/EmbeddedPig中的说明进行操作并运行以下命令时:
java -cp /pigjar/pig.jar pig_embbed.pig_java
it show: 它显示:
Error: Could not find or load main class pig_embbed.pig_java
Do anyone face this kind of situation before? 有人遇到过这种情况吗? :'(
:'(
Source code: 源代码:
package pig_embbed;
import java.util.Properties;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
public class pig_java {
public static void main(String[] args) {
try {
PigServer pigServer = new PigServer(ExecType.MAPREDUCE);
runQuery(pigServer);
Properties props = new Properties();
props.setProperty("fs.default.name",
"hdfs://<hdfs_url>:<hdfs_port>");
}catch(Exception e) {
e.printStackTrace();
}
}
public static void runQuery(PigServer pigServer) {
try {
pigServer.registerQuery("input1 = LOAD '/user/centos7/EA/test.txt' as (line:chararray);");
pigServer.registerQuery("words = foreach input1 generate FLATTEN(TOKENIZE(line)) as word;");
pigServer.registerQuery("word_groups = group words by word;");
pigServer.registerQuery("word_count = foreach word_groups generate group, COUNT(words);");
pigServer.registerQuery("ordered_word_count = order word_count by group desc;");
pigServer.registerQuery("store ordered_word_count into '/user/EA/test_output';");
} catch(Exception e) {
e.printStackTrace();
}
}
}
The classpath is wrong. 类路径错误。 In Linux, a path starting with
/
is absolute, ie from the root directory. 在Linux中,以
/
开头的路径是绝对路径,即从根目录开始的路径。 I assume you meant -cp pigjar/pig.jar
. 我假设您的意思是
-cp pigjar/pig.jar
。 You also forgot to include the current directory .
您还忘记了包括当前目录
.
, which contains your code; ,其中包含您的代码; this is included automatically in the classpath, but only if you don't actually have a
-cp
argument or CLASSPATH
environment variable. 它会自动包含在类路径中,但
-cp
是您实际上没有-cp
参数或CLASSPATH
环境变量。 The missing .
失踪者
.
is what caused this error message, but you need both changes: 是导致此错误消息的原因,但是您需要同时进行以下两项更改:
java -cp pigjar/pig.jar:. pig_embbed.pig_java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.