0

我正在 Ubuntu 12.04、Eclipse 3.7 上使用 Hadoop 1.0.3,并且正在开发一个 GUI 来使用 Windowbuider Pro 执行 Hadoop 作业。我需要从 GUI 执行包含我的代码的 jar 文件。我已经成功使用了 runtime.getruntime.exec() 方法。然而,虽然它执行特定于 DFS 的命令,但它不能执行 .jar 文件,例如与分发捆绑在一起的 PiEstimator。我的代码如下:

JButton btnYrhtrdsf = new JButton("Start Daemons");
btnYrhtrdsf.addMouseListener(new MouseAdapter() 
{
    @Override
public void mouseClicked(MouseEvent e) 
    {
    try { //WORKING
    Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/start-dfs.sh");
    Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/start-mapred.sh");
    } 
        catch (IOException e1) {
        e1.printStackTrace();
    }
    }
});
    contentPane.add(btnYrhtrdsf, "16, 10");

    JButton btnMakeDirectory = new JButton("Make Folder in HDFS");
    btnMakeDirectory.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {//WORKING
            try {
                Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/hadoop dfs -mkdir input2");
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });
    contentPane.add(btnMakeDirectory, "12, 18");

    JButton btnStopDaemons = new JButton("Stop Daemons");
    btnStopDaemons.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try { //WORKING
                Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/stop-dfs.sh");
                Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/stop-mapred.sh");
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });
    contentPane.add(btnStopDaemons, "16, 18");

    JButton btnPiestimator = new JButton("PiEstimator");
    btnPiestimator.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try { //PROBLEM!!!!!
                Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/hadoop jar hadoop-examples-1.0.3.jar pi 2 5");
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });
    contentPane.add(btnPiestimator, "14, 26");
}
4

1 回答 1

0

替换以下行

Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/hadoop jar hadoop-examples-1.0.3.jar pi 2 5");

和:

Runtime.getRuntime().exec("/usr/local/hadoop/hadoop-1.0.3/bin/hadoop jar /usr/local/hadoop/hadoop-1.0.3/hadoop-examples-1.0.3.jar pi 2 5");
于 2013-03-03T15:14:13.043 回答