从java执行hadoop示例jar文件

时间:2013-03-03 13:35:28

标签: java linux hadoop jar runtime.exec

我在Ubuntu 12.04,Eclipse 3.7上使用Hadoop 1.0.3,正在开发一个使用Windowbuider Pro执行Hadoop作业的GUI。我需要从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");
}

1 个答案:

答案 0 :(得分: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");