As a high-performance filesystem, portions of the MapR-FS file client are based on a native maprfs library. When developing an application, specifying dependence on the JAR file that includes the maprfs library allows you to build applications without having to manage platform-specific dependencies.

Writing a Java Application

In your Java application, you will use a Configuration object to interface with MapR-FS. When you instantiate a Configuration object, it is created with values from Hadoop configuration files.

When the program is build with JAR files from the MapR installation, the Hadoop 1 configuration files are in $MAPR_HOME/hadoop/hadoop-<version>/conf and the Hadoop 2 configuration files are in $HADOOP_HOME/etc/hadoop. This Hadoop configuration directory is in the hadoop classpath that you include when you compile and run the java program.

When the program is built through maven using MapR's maven artifacts, the default Hadoop configuration files are included in the maven artifacts.The user needs to programmatically update the Hadoop configuration to match the Hadoop configuration files on the MapR cluster.

Sample Code

The following sample code shows how to interface with MapR-FS using Java. The example creates a directory, writes a file, then reads the contents of the file.

This dependency will pull the rest of the dependencies from MapR's Maven repository the next time you do a mvn clean install.The JAR that includes the maprfs library is a dependency for the hadoop-core artifact.