This post will walk you through porting the Liberty MongoDB Sample application over to run on WebSphere Application Server Full Profile 126.96.36.199.
Before you start
Install a local version of WebSphere Application Server 188.8.131.52 (the full profile) and a MongoDB server to run against.
- Download and unjar the Liberty MongoDB sample application.
- Copy the MongoDB configuration from
mongoDBSample.jarwlpusrserversmongoDBSampleserver.xmlinto a new file named
ibm-mongodb.xmlwith a root element of
<ibm-mongodb>. You will end up with something like this (you can modify the configuration settings as necessary):
<ibm-mongodb> <mongo id="mongo" libraryRef="mongo-lib" hostNames="localhost" ports="27017"/> <mongoDB jndiName="mongo/sampledb" mongoRef="mongo" databaseName="sampleDb"/> </ibm-mongodb>
- Install the newly created configuration file into the application server’s configuration repository. If in the future you need to make configuration changes, you’ll need to manually edit this file in place and restart the server; the file is only processed at server start. To install this file:
wsadmin(make sure your app server is running):
C:<was_home>binwsadmin.bat -lang jython
- Run the following commands (replace <...> with the values for your system):
AdminConfig.createDocument("cells/<cell_name>/nodes/[node_name]/servers/<server_name>/ibm-mongodb.xml", "<path_to>/ibm-mongodb.xml") AdminConfig.save()
If the commands were successful, the MongoDB configuration in now installed into the WebSphere Application Server configuration tree.
The MongoDB configuration must be scoped to an individual application server and it can’t be installed at any other levels. Also, there is no console support. If for some reason you don’t want to use the MongoDB support any longer, you can use AdminConfig to remove this document.
- Install the application that is packaged inside of the Liberty MongoDB sample (
- Log into the administrative console.
- Install the application to the server on which you installed the MongoDB configuration.
- Whilst going through the wizard, accept the default values and keep clicking Next.
- On Step 3, you’ll need to specify the target JNDI name for the resource reference
mongodb/sample. In the Target Resource JNDI Name field, type
- In Step 5 of the wizard, set the context root to
- Save the changes to the master configuration.
At this point we have added the MongoDB configuration to the WebSphere configuration and installed the application.
- Configure a shared library so that the MongoDB Java driver classes are available to the server and the application:
- Download Version 2.10.0 or later of the MongoDB Java driver to the same file system as WebSphere Application Server.
- In the administrative console, navigate to Environment > Shared Libraries > New….
- Choose a name for this shared library (ie:
mongodb), and configure the classpath to reference the newly downloaded driver.
- Select the Use an isolated class loader for this shared library check box.
- Navigate back to the application (Applications > WebSphere Enterprise Applications > mongoDBApp_war) configuration that was installed in Step 4 and click the Shared library references link.
- On the next page, click the first box and then click the Reference shared libraries button.
- Select the shared library that was created in Step 5 and click the arrow pointing to the right to add the reference. Then click OK and save the changes to the master configuration.
- At this point everything is fully configured. Restart the application server and if all works as expected, you should see a
CWKKD0112message indicating that the MongoDB service started successfully. Point your web browser to http://localhost:9080/mongodb (you might have to change the port depending on your installation). If you don’t see ‘HelloMongo!’ review the server logs for any error messages that might indicate what the problem is.