I guess my TDD skills has slowly melted down as I was not actively programming more than six f*king months! I need a kickstart to refresh my laggy old brain and naggy Macbook Pro Yosemite OSX (upgrades needed).
export PATH=$PATH:$MAVEN_HOME/bin
export MONGO_HOME=/usr/local/<Mongo Extracted Folder>
export PATH=$PATH:$MONGO_HOME/bin
What do you need?
- Maven 3.x
- MongoDB 3.x
- Java JDK 1.7.x
- Eclipse IDE Java EE Developer (mine is Luna with m2e plugin installed)
What are the steps?
- Create a mongodb collection & document
- Create a java web project And Import to Eclipse IDE
- Add project dependencies: Spring core, Spring test, Spring data mongo etc...
- Write you TDD code. "Red -> Green -> Refactor" cycle.
A. Create a mongodb collection & document
- Start your mongod: mongodb -dbpath <choose your db path i.e.: /usr/local/var/mongodb/data> &
- Start your mongo shell, type: mongo --shell
- In shell, create your db collection, type: use <choose your db i.e.: demo>
- In shell, create one entry, type: db.demo.insert({name: "hamid", socialSecurity: 1234567890})
- In shell, verify your entry, type: db.demo.find()
B. Create java web project (please make sure you're connected to the internet)
- In command line, navigate to your eclipse workspace folder. If there isn't existing, create one.
- Create java web project (just hit enter on interactive prompt), type: mvn archetype:generate -DgroupId=<choose one i.e.: com.pointcut.demo> -DartifactId=<choose one i.e.: springmongo> -DarchetypeArtifactId=maven-archetype-webapp
- On "BUILD SUCCESS" (after a long while), navigate to your project folder (i.e.: springmongo) to get your project eclipse ready, type: mvn eclipse:clean eclipse:eclipse
- Import into eclipse IDE: Goto menu File->Import->Maven->Existing Maven Projects and locate your project in your workspace folder.
- Make sure you project points to the right JDK runtime in Java Build Path: Right click on project name->Build Path->Configure Build Path...
C. Add project dependencies: Spring core, Spring test, Spring data mongo
- Add project dependencies: Right click on project name->Maven->Add Dependency
- In "Add Dependency" window, type "spring-core" in "Enter groupId, artifactId or sha1 prefix or pattern (*)" field
- Choose related library from "Search Results" list choose "org.springframework spring-core"-> 4.0.2.RELEASE version
- Repeat previous two (2) steps for spring-test (4.0.2.RELEASE), spring-context (4.0.2.RELEASE), spring-context-support (4.0.2.RELEASE), spring-beans (4.0.2.RELEASE), spring-data-mongodb (1.2.0.RELEASE), spring-beans (4.0.2.RELEASE), mongo-java-driver (2.9.1)
- Update your maven project: Right click on project name ->Maven->Update Project...
What's next? checkout PART 2 coming soon...
-----------------------------✄----------------------------
Installation Guide
How to install? I love using command line if all possible. ok briefly this is what I did via command line, at least.For Maven 3.x
- Download the archive from here. In command line, wget <archive url address>
- Unzip it. For my case at /usr/local. Depending on your archive (.zip or tar.gz) u may want to user unzip or tar zxvf in command line.
- Set the home var and path. Update your .bash_profile (I use vi), scroll all the way down and insert the following lines:
export PATH=$PATH:$MAVEN_HOME/bin
For Mongo DB 3.x (recommend 64-bit)
- Download the archive from here. Again, in command line wget <archive url address>
- Unzip it. For my case at /usr/local. Depending on your archive (.zip or tar.gz) u may want to user unzip or tar zxvf in command line.
- Set the home var and path. Update your .bash_profile (I use vi), scroll all the way down and insert the following:
export MONGO_HOME=/usr/local/<Mongo Extracted Folder>
export PATH=$PATH:$MONGO_HOME/bin
No comments:
Post a Comment