October 14, 2014 | Written by: Tony Abdulla
Categorized: Community | How-tos
Share this post:
This was originally posted on the Cloudant.com blog but we wanted to ensure it received visibility to you here. The Cloudant team is thrilled to be the data layer behind Bluemix and we’re excited to have released a new IBM Bluemix boilerplate for building apps with Java and Cloudant. Cloudant has a lot of exciting updates coming for Bluemix users in the near future. Be on the lookout for more boilerplates, features, sample apps, and tutorials.
Related | Get Started with Cloudant on Bluemix
This tutorial will walk you through getting set up on IBM Bluemix and building your first app using the new Java boilerplate.
You’ll need a Bluemix account. If you don’t already have one, go to https://ace.ng.bluemix.net/ and sign up in the top right corner.
You’ll also need to download ‘cf,’ the Bluemix command line tool. You can download it here.
Once you’ve signed in to Bluemix, navigate to the ‘catalog’ tab and click on the Java+Cloudant boilerplate
You will then be taken to the initialization page for the boilerplate.
On the right-hand side you are asked to name your application. I’ve named mine “CloudantJavaTest’ so you can’t use that one, but pick something similar and then hit ‘Create.’
Behind the scenes, Bluemix will provision space on its infrastructure for your application. The amount of space used depends on the app stack used. In this case, you will get 512MB of memory for this app. While Bluemix provisions space, Cloudant is creating a free account for you on one of our multi-tenant clusters.
After creating your app you’ll be taken to the ‘Overview’ page where you will see your run time environment and your Cloudant instance in the ‘Development Services’ section.
You can easily find your Cloudant credentials by clicking ‘show credentials’ on the service tile or through VCAP_SERVICES (see below.) This Cloudant account acts like any other in that it has a username, password, and endpoint URL for its REST API. The only difference is that this account can be deleted from Bluemix if you delete your application.
To view a quick-start guide for developing your app click the “View Guide” tab toward the top. (A fun pop-up will appear.) You will also see a link to download this app to your local machine for editing the code. The screen shot below is new, to show what it looks like in the updated Bluemix UI. So don’t be too confused if you’ve made it this far.
Within your application, your Cloudant credentials can be accessed through the VCAP_SERVICES environmental variable. You can see this variable in the Runtime tab
Within the boilerplate application code there is an example of how to access this variable in the runtime environment.
Once you’ve downloaded your application you can make any changes you would like to the code. When you are done, push the application back to Bluemix for building and running. To do so, you must first log in to Bluemix with cf:
$ cf login
> username: <USERNAME>
> password: <PASSWORD>
then from the root directory of your application:
$ cf push
This will build and push the application to Bluemix. You can visit the URL http://(yourappname).mybluemix.net and see the example app, which is a place to upload your favorite files (I use mine for useful gifs):
With this boilerplate you will have all the tools for building an app within Bluemix using the Java Runtime and linking it to Cloudant.
We have many more exciting features, boilerplates, and tutorials revolving around Cloudant and Bluemix coming this year. Do you have anything you would like to see? Let us know!