2013-03-03 126 views
0

我正在Ubuntu 12.04和Eclipse 3.7上使用Hadoop 1.0.3,並且正在開發一個使用Windowbuider Pro執行Hadoop作業的GUI。我需要從GUI執行包含我的代碼的jar文件。 我已經使用runtime.getruntime.exec()方法取得了一些成功。但是,雖然它執行特定於DFS的命令,但它不能執行.jar文件,例如捆綁在發行版中的PiEstimator。 我的代碼如下:從java執行hadoop示例jar文件

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

回答

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");