In this simple how to I will let you know how to add the mongodb driver as a module to the Wildfly application server. In case you don’t know about Wildfly please follow the link : http://www.wildfly.org. Currently Wildfly is the only open source JEE7 application server/container offering full scale implementations of all the JEE7 APIs with full clustering, yes for free! Having a thriving community and a lot of documentation is a must chose must have if you are trying to ride the wave of new software technologies in the JEE world.MongoDB is a document oriented NoSQL store.If you have no idea about it read here.
Changes and more changes
When Wildfly was out , I was amazed on how much the JBoss team decided to take drastic step to easy the pain of classloading in the new version of their application server. All of us have been used to leave with the cumbersome hierarchical class loading model of previous versions of appservers. Many of us loved it, but when time was coming to tweak it, we were facing the real deal. Then people how could manipulate it and make it work correctly were conceived as some kind of mages or skilled elfs. All this changed dramatically. Now the class loading model has been simplified and the dependency management is left to be handled entirely by the developer who is totally responsible for defining deps and libs to be loaded. Also between apps by default the system offers class loading isolation. Some people argue about it being bad…but probably they have never faced the hierarchical classloader. We lived with it for to many years.I would say RIP and thank you but Wildfly is here.
One of the cool features that I love is the new modules system. You can define jars as modules and refer to them to your application and have then being served as dependencies in your application. On that aspect libs and jars commonly used by many applications, like database drivers or connectivity suites, can be declared as part of resources of the application server and to be sharable among different deployments. The way to manipulate and define that is either by defining entries in the MANIFEST.MF file of your application or by defining a specific xml descriptor which is called jboss-deployment-structure.xml bundled with your application.These file describe the deps of your application to external libraries and with the later you can fine grain even deps in really package level.
A “simple” implementation of a moduling system. Simple with clear capabilities and limitations. You define your module under the $WILDFLY_HOME/modules/ with a package like naming and the last inner file is named main/ containing the jar you want and the file that describes dependencies for the jar to be loaded successfully, file named module.xml. That’s all folks. You don’t need anything else.
Wildfly and MongoDB driver
To work please download/install :
- WildflyAS application server
- MongoDB driver
Step 1 Create the directory in the modules directory.
Go into your wildfly home directory and
mkdir -p org/mongodb/main/
Now copy the mongo driver jar in to the same directory.Open module.xml file and enter the following :
<module xmlns=”urn:jboss:module:1.1″ name=”org.mongodb”>
<module name=”javax.transaction.api” optional=”true”/>
<module name=”javax.servlet.api” optional=”true”/>
And yes you are done.