I'm newbie in Hadoop cluster node.
I try running Hadoop command in java
The following code is to copy file from local to HDFS.
When I use command shell, it is working:
hadoop fs -copyFromLocal /home/my_name/tutorial_append.txt /user/my_name/tutorial_append.txt
But when I implement it in java code like this:
import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class UploadTest {
public static void main(String[] args) throws IOException {
System.out.print("Hello World");
String localPath="/home/my_name/tutorial_append.txt";
String uri ="hdfs://0.0.0.0:8020";
String hdfsdir="hdfs://0.0.0.0:8020/user/my_name/";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri),conf);
fs.copyFromLocalFile(new Path(localPath),new Path(hdfsdir));
}
}
compile javac -cp hadoop-core-1.2.1.jar UploadTest.java
run java -cp hadoop-core-1.2.1.jar UploadTest
Error: Could not find or load main class UploadTest
I have tried it many times but I've been unsuccessful.
SOLVED
Finally I build to jar file's and I run using hadoop jar UploadTest.jar
I was following this
Hadoop Error: Could not find or load main class class path TestJava