簡體   English   中英

無法在Ubuntu中運行Pig嵌入式Java程序

[英]Unable to run Pig Embbeded Java Program in Ubuntu

最近,我對Apache Pig進行了研究,並嘗試構建Pig-Embedded Java程序。 我從網站(從https://acadgild.com/blog/embedding-pig-java/ )找到並復制了一個示例,然后在運行之前嘗試對其進行編譯。

javac pig_java.java

編譯成功,沒有提示任何錯誤。 但是,當我按照https://wiki.apache.org/pig/EmbeddedPig中的說明進行操作並運行以下命令時:

java -cp /pigjar/pig.jar pig_embbed.pig_java

它顯示:

Error: Could not find or load main class pig_embbed.pig_java

有人遇到過這種情況嗎? :'(

源代碼:

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

類路徑錯誤。 在Linux中,以/開頭的路徑是絕對路徑,即從根目錄開始的路徑。 我假設您的意思是-cp pigjar/pig.jar 您還忘記了包括當前目錄. ,其中包含您的代碼; 它會自動包含在類路徑中,但-cp是您實際上沒有-cp參數或CLASSPATH環境變量。 失蹤者. 是導致此錯誤消息的原因,但是您需要同時進行以下兩項更改:

java -cp pigjar/pig.jar:. pig_embbed.pig_java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM