3

I have multiple .java files for my hadoop project. How do I execute them without using eclipse?

PS: I use the default ubuntu terminal

user1291453
  • 133
  • 3
  • 12

3 Answers3

1

You can use javac *.java to compile all the files in the current working directory. As for executing them, use java filename
Where the filename does NOT have the .class at the end. IE, you have MyProgram.java which compiles into MyProgram.class you would type: java MyProgram

You want the run the main class of your project btw (slightly vague, but it might be the only one with a main method).

Youssef G.
  • 617
  • 4
  • 10
0

You will need to compile your .java files into a jar and then use the hadoop jar command to execute it. If your code has external dependencies, you will need to either use the -libjars flag or create a fat jar.

Community
  • 1
  • 1
Matt D
  • 3,055
  • 1
  • 18
  • 17
  • I linked how to do so with Eclipse, but here is an example for how to do so with Ant: http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html#four-steps – Matt D Apr 11 '12 at 18:01
0

Following is the simple steps for compiling hadoop java files and executing programs:

Compile:

javac -classpath < HADOOP_INSTALL_DIR>/hadoop-< Version>.jar -d < OUTPUT_DIR_NAME> ( < YOUR_MUTLIPLE_JAVAFILES_PATH> --like *.java)

Build jar file:

jar cvf < YOUR_JAR_FILE_PATH_WITH_NAME> -C <(previous compiled output)OUTPUT_DIR_NAME>

Run Hadoop program using Hadoop Jar command:

hadoop jar < JAR_FILE_PATH> < MAIN_PROGRAM_NAME_IN_JAR> < INPUT_PARAMETERS_IF-ANY>

Hope this helps!