Migrating an Apache Table to MongoDB: Creating a Maven Project in Eclipse

Next, create a Java project in Eclipse IDE for migrating Cassandra database data to MongoDB database.

  1. Select File >■ New >■ Other.
  2. In the New window, select Maven ► Maven Project and click on Next as shown in Figure 6-3.

  1. The New Maven Project wizard gets started. Select the Create a simple project check box and the Use default Workspace location check box and click on Next as shown in Figure 6-4.

  1. In Configure project, specify the following and then click on Finish as shown in Figure 6-5.
  • Group Id: com.mongodb.migration
  • Artifact Id: CassandraToMongoDB
  • Version: 1.0.0
  • Packaging: jar
  • Name: CassandraToMongoDB

A Maven Project gets created in Eclipse IDE as shown in Figure 6-6.

Now we need to create two Java classes for the migration: one to create the initial data in Cassandra and the other to migrate the data to MongoDB.

  1. To create a Java class click on File ► New ► Other.
  2. In the New window, select Java ► Class and click on Next as shown in Figure 6-7.

  1. In New Java Class wizard select the Source folder as CassandraToMongoDB/ src/main/java and specify Package as mongodb and class name as CreateCassandraDatabase. Select the check box to create method stub public static void main(String[] args). Click on Finish as shown in Figure 6-8.

4. Similarly create a Java class MigrateCassandraToMongoDB as shown in Figure 6-9.

he two Java classes are shown in the Package Explorer in Figure 6-10.

We need to add some dependencies to the pom.xml. Add the following dependencies listed in Table 6-1; some of the dependencies are indicated as being included with the Apache Cassandra Project dependency and should not be added separately.

The pom.xml is listed below.

<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>com.mongodb.migration</groupId>

<artifactId>CassandraToMongoDB</artifactId>

<version>1.0.0</version>

<name>CassandraToMongoDB</name>

<dependencies>

<dependency>

<groupId>org.mongodb</groupId>

<artifactId>mongo-java-driver</artifactId>

<version>3.0.3</version>

</dependency>

<dependency>

<groupId>com.datastax.cassandra</groupId>

<artifactId>cassandra-driver-core</artifactId>

<version>2.2.0-rc2</version>

</dependency>

<dependency>

<groupId>org.apache.cassandra</groupId>

<artifactId>cassandra-all</artifactId>

<version>2.2.0</version>

</dependency>

<dependency>

<groupId>commons-beanutils</groupId>

<artifactId>commons-beanutils</artifactId>

<version>1.9.2</version>

</dependency>

<dependency>

<groupId>commons-collections</groupId>

<artifactId>commons-collections</artifactId>

<version>3.2.1</version>

</dependency>

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.2</version>

</dependency>

</dependencies>

</project>

Some of these dependencies have further dependencies, which get added automatically and should not be added separately. To find the required Jars that get added from the dependencies, right-click on the project node in Package Explorer and select Properties. In Properties select Java Build Path. The Jars added to the migration project are shown in Figure 6-11.

Source: Vohra Deepak (2015), Pro MongoDB™ Development, Apress; 1st ed. edition.

Leave a Reply

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