The kundera-mongo library is available as a Maven dependency. We shall use a Maven project to access MongoDB with the kundera-mongo library for which to create a Maven project in Eclipse IDE.
- Select File ➤ New ➤ Other in Eclipse IDE.
- Select Maven ➤ Maven Project in the New window as shown in Figure 9-2.
Click on Next.
3. In New Maven Project wizard select the Create a simple project check box. Also select the Use default Workspace location check box as shown in Figure 9-3. Click on Next.
- In the New Maven wizard’s Configure project window, select the following values and click on Finish as shown in Figure 9-4.
- Group Id: com.kundera.mongodb
- Artifact Id: KunderaMongoDB
- Version: 1.0.0
- Packaging: jar
- Name: KunderaMongoDB
A Maven project for Kundera Mongo gets created as shown in the Package Explorer in Figure 9-5.
- Next, modify the pom.xml to add dependencies for the kundera-mongo library and EclipseLink. As we shall be using JPA, EclipseLink is required.
<dependencies>
<dependency>
<groupId>com.impetus.client</groupId>
<artifactId>kundera-mongo</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
- In the build configuration specify the maven-compiler-plugin plug-in to compile the Maven project and the exec-maven-plugin plug-in to run the Maven client class. For the exec-maven-plugin plug-in specify the main class to run in the <configuration/> as the Kundera Client class kundera.KunderaClient, which we shall create later in the chapter.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>kundera.KunderaClient</mainClass>
</configuration>
</plugin>
</plugins>
</build>
The pom.xml is listed:
<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.kundera.mongodb</groupId>
<artifactId>KunderaMongoDB</artifactId>
<version>1.0.0</version>
<name>KunderaMongoDB</name>
<dependencies>
<dependency>
<groupId>com.impetus.client</groupId>
<artifactId>kundera-mongo</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>kundera.KunderaClient</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Source: Vohra Deepak (2015), Pro MongoDB™ Development, Apress; 1st ed. edition.