BinaryMee
BinaryMee

Reputation: 2142

How to run Hadoop command from JSP

TO run a hadoop program the command used is

hadoop/bin/hadoop jar hadoop/Anagram.jar com.hadoop.examples.anagrams.AnagramJob /user/hadoop-user/testdir /user/hadoop-user/outputdir

From PWD.

I need to run this command from a JSP page hosted in APACHE TOMCAT 7.0. TO run linux command in JSP.

out.println(Runtime.getRuntime().exec("mkdir /tmp/testdirectory"));

Its working fine. But i need to run this hadoop command.

In reference to this question, I have done like this

  <%
try{

out.println(Runtime.getRuntime().exec("start-all.sh"));
ProcessBuilder pb = new ProcessBuilder("hadoop jar hadoop/Anagram.jar com.hadoop.examples.anagrams.AnagramJob /user/hadoop-user/testdir /user/hadoop-user/outputdir5677");
pb.directory(new File("/home/hadoop-user/hadoop/bin/"));
Process p = pb.start();

}
catch(Exception e)
{ out.println("Error"+e);
}
%>

But it is throwing the exception

java.lang.UNIXProcess@5a8a7e Errorjava.io.IOException: Cannot run program "hadoop jar hadoop/Anagram.jar com.hadoop.examples.anagrams.AnagramJob /user/hadoop-user/testdir /user/hadoop-user/outputdir5677" (in directory "/home/hadoop-user/hadoop/bin"): java.io.IOException: error=2, No such file or directory

When i use like this How can i resolve my problem. I need to run this command. but this problem is related to path. :( Any help would be appreciated!!

Upvotes: 1

Views: 1790

Answers (2)

Amareswar
Amareswar

Reputation: 2064

ProcessBuilder takes comma separated arguments, not the entire command like in post. Search for ProcessBuilder examples

Upvotes: 0

Will Hartung
Will Hartung

Reputation: 118631

Try: ./hadoop jar hadoop/Anagram.jar ...

The PATH used is likely not containing the ".", or current directory.

This will make it search the bin directory that you're in.

Upvotes: 1

Related Questions