You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Ved Prakash <me...@gmail.com> on 2009/02/12 12:58:13 UTC

how to use FileSystem Object API

I m trying to run following code

public class localtohdfs {
public static void main()
{
          Configuration config = new Configuration();
          FileSystem hdfs = FileSystem.get(config);
          Path srcPath = new Path("/root/testfile");
          Path dstPath = new Path("testfile_hadoop");
          hdfs.copyFromLocalFile(srcPath, dstPath);
}
}

when I do javac i see
[root@nlb-2 hadoop-0.17.2.1]# javac localtohdfs.java
localtohdfs.java:3: package org.apache.hadoop does not exist
import org.apache.hadoop.*;
^
localtohdfs.java:7: cannot find symbol
symbol  : class Configuration
location: class localtohdfs
          Configuration config = new Configuration();
          ^
localtohdfs.java:7: cannot find symbol
symbol  : class Configuration
location: class localtohdfs
          Configuration config = new Configuration();
                                     ^
localtohdfs.java:8: cannot find symbol
symbol  : class FileSystem
location: class localtohdfs
          FileSystem hdfs = FileSystem.get(config);
          ^
localtohdfs.java:8: cannot find symbol
symbol  : variable FileSystem
location: class localtohdfs
          FileSystem hdfs = FileSystem.get(config);
                            ^
localtohdfs.java:9: cannot find symbol
symbol  : class Path
location: class localtohdfs
          Path srcPath = new Path("/root/testfile");
          ^
localtohdfs.java:9: cannot find symbol
symbol  : class Path
location: class localtohdfs
          Path srcPath = new Path("/root/testfile");
                             ^
localtohdfs.java:10: cannot find symbol
symbol  : class Path
location: class localtohdfs
          Path dstPath = new Path("testfile_hadoop");
          ^
localtohdfs.java:10: cannot find symbol
symbol  : class Path
location: class localtohdfs
          Path dstPath = new Path("testfile_hadoop");
                             ^
9 errors

CLASS_PATH="/root/newhadoop/hadoop-0.17.2.1/src/java:/root/newhadoop/hadoop-0.17.2.1/conf:/usr/java/jdk1.6.0/lib"
PATH="/usr/java/jdk1.6.0/bin:/usr/local/apache-ant-1.7.1/bin:/root/newhadoop/hadoop-0.17.2.1/bin:/usr/lib/jvm/java-1.5.0-sun-1.5.0.13/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
HADOOP_HOME="/root/newhadoop/hadoop-0.17.2.1"
JAVA_HOME="/usr/java/jdk1.6.0/"

Where is the problem?

thanks and regards!

Re: how to use FileSystem Object API

Posted by ChingShen <ch...@gmail.com>.
you have to specify a hadoop-xxx-core.jar file.

for example:
javac -cp hadoop-xxx-core.jar localtohdfs.java


On Thu, Feb 12, 2009 at 7:58 PM, Ved Prakash <me...@gmail.com>wrote:

> I m trying to run following code
>
> public class localtohdfs {
> public static void main()
> {
>          Configuration config = new Configuration();
>          FileSystem hdfs = FileSystem.get(config);
>          Path srcPath = new Path("/root/testfile");
>          Path dstPath = new Path("testfile_hadoop");
>          hdfs.copyFromLocalFile(srcPath, dstPath);
> }
> }
>
> when I do javac i see
> [root@nlb-2 hadoop-0.17.2.1]# javac localtohdfs.java
> localtohdfs.java:3: package org.apache.hadoop does not exist
> import org.apache.hadoop.*;
> ^
> localtohdfs.java:7: cannot find symbol
> symbol  : class Configuration
> location: class localtohdfs
>          Configuration config = new Configuration();
>          ^
> localtohdfs.java:7: cannot find symbol
> symbol  : class Configuration
> location: class localtohdfs
>          Configuration config = new Configuration();
>                                     ^
> localtohdfs.java:8: cannot find symbol
> symbol  : class FileSystem
> location: class localtohdfs
>          FileSystem hdfs = FileSystem.get(config);
>          ^
> localtohdfs.java:8: cannot find symbol
> symbol  : variable FileSystem
> location: class localtohdfs
>          FileSystem hdfs = FileSystem.get(config);
>                            ^
> localtohdfs.java:9: cannot find symbol
> symbol  : class Path
> location: class localtohdfs
>          Path srcPath = new Path("/root/testfile");
>          ^
> localtohdfs.java:9: cannot find symbol
> symbol  : class Path
> location: class localtohdfs
>          Path srcPath = new Path("/root/testfile");
>                             ^
> localtohdfs.java:10: cannot find symbol
> symbol  : class Path
> location: class localtohdfs
>          Path dstPath = new Path("testfile_hadoop");
>          ^
> localtohdfs.java:10: cannot find symbol
> symbol  : class Path
> location: class localtohdfs
>          Path dstPath = new Path("testfile_hadoop");
>                             ^
> 9 errors
>
>
> CLASS_PATH="/root/newhadoop/hadoop-0.17.2.1/src/java:/root/newhadoop/hadoop-0.17.2.1/conf:/usr/java/jdk1.6.0/lib"
>
> PATH="/usr/java/jdk1.6.0/bin:/usr/local/apache-ant-1.7.1/bin:/root/newhadoop/hadoop-0.17.2.1/bin:/usr/lib/jvm/java-1.5.0-sun-1.5.0.13/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
> HADOOP_HOME="/root/newhadoop/hadoop-0.17.2.1"
> JAVA_HOME="/usr/java/jdk1.6.0/"
>
> Where is the problem?
>
> thanks and regards!
>