Compiling and Running Java OJAI Applications

For applications that use the Java OJAI API, use Maven to compile and determine the application's dependencies. Then, when you run the application, specify those dependencies in the application's classpath.

Compile and Determine Dependencies

Use Maven to compile and determine the application dependencies.
  1. Add MapR's Maven repository to your pom.xml file, if it is not already added:
    <repositories>
        <repository>
            <id>mapr-releases</id>
            <url>http://repository.mapr.com/nexus/content/repositories/releases</url>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
        </repository>
    </repositories>
  2. Add a dependency to the MapR OJAI driver project:
    <dependencies>
        <dependency>
            <groupId>com.mapr.ojai</groupId>
            <artifactId>mapr-ojai-driver</artifactId>
            <version>6.0.0-mapr</version>
        </dependency>
    </dependencies>
    Note: Replace the <version> property with the MapR-DB version that you are using.
  3. Use Maven to compile the application and resolve dependencies.

Run the Application

When you develop a Java application, you can use a dependency management tool such as Maven to compile your application. However, it is recommended that do the following instead:
  1. Compile the Java application without including dependencies
  2. Specify the required classpath when you submit the application to the cluster
If you choose to bundle the JAR file, and there is a mismatch between the bundled JAR file and the version that your MapR cluster expects, this can result in failures. The failures differ depending on the version of MapR you are using. For more information, see Using the MapR-FS JAR to Connect to the Cluster.

When the cluster is secure, the node must also have a MapR ticket configured for the user that runs the application.

You can use the following command to launch MapR-DB JSON applications:
java -cp <classpath>:. -Djava.library.path=/opt/mapr/lib <main class JAR> <command line arguments>

Enable OJAI Tracing

To help debug your Java OJAI application, you can enable OJAI tracing. MapR uses the log4j API to log tracing messages. To enable writing these messages to standard output, follow these steps:

  1. Set the following property in your /opt/mapr/conf/log4j.properties file:
    log4j.logger.com.mapr.ojai.store.impl=TRACE, stdout
  2. Add the following to your java launch command:
    • In your java classpath, add the library that includes custom MapR log4j classes:
      -cp /opt/mapr/lib/central-logging-6.0.1-mapr.jar:<other classpaths>:.
    • Define the location of the log4j.properties file:
      -Dlog4j.configuration=file:/opt/mapr/conf/log4j.properties