Using Maven to Develop GridDB Applications

Introduction

In this post, we will go through common steps involved in configuring Maven for a project that uses the GridDB Java API.
This blog assumes you have both GridDB and Maven installed correctly. If you do not yet have GridDB installed, you can refer to the beginning portion of this blog. Maven can be installed using this method.

Table of Contents

Installing the GridDB Jar

First, you need to install gridstore.jar into your local Maven repository.

mvn install:install-file -Dfile=/usr/share/java/gridstore.jar -DgroupId=com.toshiba.mwcloud \
    -DartifactId=gs -Dversion=4.0 -Dpackaging=jar

Create Your Project

For this sample project we’ll use the Sample1.java which is used in many of the GridDB blogs and tutorials. We will create the Maven POM file, “pom.xml” which configures the project. If you’re familiar with Maven POM files already, the only GridDB specific portion is adding the dependency:

    <packaging>jar</packaging>
 <dependencies>
        <dependency>
        <groupId>com.toshiba.mwcloud</groupId>
        <artifactId>gs</artifactId>
        <version>4.0</version>
</dependency>

The full pom.xml will look like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.griddb.sample.gsSample</groupId>
  <artifactId>Sample1</artifactId>
  <version>0.0.1</version>
  <packaging>jar</packaging>
  <name>Sample1</name>
    <url>http://maven.apache.org</url>
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
        <groupId>com.toshiba.mwcloud</groupId>
        <artifactId>gs</artifactId>
        <version>4.0</version>
        </dependency>
    </dependencies>
</project>

Your POM file should now be set up correctly to run Maven and should be placed in a separate directory that we will use to organize the project such as “mavenSample”. Inside the base level directory there will be the pom that was just created and you will need to create a new directory structure and download Sample1.java.

$ mkdir -p src/main/java/net/griddb/sample/gsSample/
$ curl https://raw.githubusercontent.com/griddb/griddb_nosql/master/docs/sample/program/Sample1.java > \
src/main/java/net/griddb/sample/gsSample/Sample.java

Now you need to edit src/main/java/net/griddb/sample/gsSample/Sample1.java changing package gsSample; to package net.griddb.sample.gsSample;

Build and Execute

Now, to run maven, simply navigate to your mavenGridDBJavaConnectorTest folder and run the following commands:

mvn clean package
mvn package exec:java -Dexec.mainClass="net.griddb.sample.gsSample.Sample1" -Dexec.args="239.0.0.1 31999 defaultCluster admin admin"

If the build and execution was successful, the following should be displayed:

Person:  name=name02 status=false count=2 lob=[65, 66, 67, 68, 69, 70, 71, 72, 73, 74]

Once confirmed, we are finished. You should now be able to use Maven to build and run your GridDB projects.

References

If you have any questions about the blog, please create a Stack Overflow post here https://stackoverflow.com/questions/ask?tags=griddb .
Make sure that you use the “griddb” tag so our engineers can quickly reply to your questions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.