blog 1blog 2blog 3

MongoDB, EclipseLink and Eclipse connection for our Webapp

This is the tutorial on  how to set up a development environment for 3 tier web application development. This post is just a collection of step by step instructions until now.

Nevertheless, I hope you can draw something useful from these step by step instructions until then.


Installing and configuring :
  • MongoDB 2.6.x
  • MonjaDB
  • EclipseLink 2.5
How to setup MongoDB
  • Go to -> Download Windows 64bit (32bit)msi installer
  • Run the installer -> Next -> check License Agreement -> Next -> Custom -> Choose your favorite install location -> Next -> Install -> Finish
  • Go to your installation directory and create the folder structure “/data/db”.
  • Go to your installation directory and create a folder named “log”.
  • In the installation directory create a file named “mongod.cfg” -> open file -> type the mongod.cfg snippet (see below)
  • In the installation directory create a file named “mongoStart.bat” -> open file (e.g. with notepad) -> type “C:\path\to\mongo\bin\mongod.exe –config C:\path\to\mongo\mongod.cfg”
  • DB Startup: doubleclick mongoStart.bat
  • DB Shutdown: in command prompt type CTRL+C -> J -> Enter
  • All log files are created in the log directory and can be read with notepad or a text editor
  • (optional) If you are running Windows7 AND you are getting Errorcode 33 while running MongoDB -> Install
How to install MonjaDB Eclipse Plugin
  • Install MonjaDB Plugin
    • Help -> Eclipse Marketplace -> type “MonjaDB” -> Install -> Confirm -> I accept the terms of the license agreement -> Finish (Installs Monja DB for easier DB development)
    • Window -> Perspectives -> Other -> MonjaDB (opens the perspective for Monja DB. One can switch back to the normal perspective by clicking on “JavaEE” in the right top corner of Eclipse)
    • To connect to a running MongoDB click on the leftmost icon of the “DB Tree” view -> ConnectionType=Normal / No SSH Configuration / Host= / Port=27017 / Database=test -> OK
How to configure a DynamicWebProject for MongoDB + EclipseLink
  • Setup MongoDB and EclipseLink
    • R-Click project -> Maven -> Add Dependency -> org.eclipse.persistence.jpa / org.eclipse.persistence.nosql / mongo-java-driver / org.apache.tomcat servlet api / javax javaee-api
    • R-Click on “src” folder -> New -> Other -> General -> Folder -> Name it “META-INF”
    • R-Click on “META-INF” folder -> New -> Other -> File -> Name it “persistence.xml” (This is where you are configuring )
    • insert persistence.xml snippet (see below)
 destination: file
 path: ‘C:\\path\\to\\mongo\\log\\mongo.log’
 dbPath: ‘C:\\path\\to\\mongo\\data’
<persistence xmlns=”” xmlns:xsi=”” xsi:schemaLocation=” persistence_2_0.xsd” version=”2.0″> 
<persistence-unit name=”<unitname>” transaction-type=”RESOURCE_LOCAL”> 
<property name=”” value=”org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform”/> 
<property name=”eclipselink.nosql.connection-spec” value=”org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec”/> 
<property name=”” value=”<xxxxx>, 27017″/>
<property name=”” value=”<host1>, localhost”/> 
<property name=”” value=”<dbname>”/> 
<property name=”eclipselink.logging.level” value=”FINEST”/>