Getting started with a normal Java project can be a bit daunting but add in some of the latest things that developers want, such as microservices and cloud native, and the time to actually having something up-and-running has just gone up drastically!
The diagram below shows a high level view of the steps you take according to whether you prefer to use a GUI or a command line.
Overview of code creation to deployment
So, let’s create a Java microservice …
Step 1: choose your starting point
You can create a new Java microservice either through the Bluemix console, or using the new command line. To use the command line,
If you’re using the Bluemix console, select the Create Project option. After that it is the same for both interfaces: select Microservice, Basic, and then Java.
Step 2: add some services
You can now add some data services to your project. Currently, you can pick from Cloudant or Object-Storage (or both if you want!). The really great thing is that these services will be provisioned automatically for you; no need to remember to create and bind them at a later point in time. Even better than that, the code that is generated for you will contain all the code you need to connect to these services using current best practices. So, in the case of the Java microservice, you will be given CDI injected connectors to your services all ready to be used in your code.
Step 3: download the code for local development
After making your selections, you’ll want to download the code and see what it looks like. If you’re using the CLI then this is automatically done for you; if you’re using the console, then you’ll need to click on the Generate Code button and then download it once it’s been created. At this point you can optionally do some local development on the code. A really cool feature here is that if you added services to your project in the previous steps, your local Java runtime will be using those cloud services rather than having to mock out the calls when running locally.
Step 4: deployment
There are a couple of ways you can now deploy your code to Bluemix. You can push it into a Github repository, at which point a Create toolchain button will appear: click on that and it will create a toolchain in Bluemix that pulls the code from your repository and deploys it. Alternatively you can use the CLI to run the
bx dev deploy command that will deploy it for you. If you want to check on what’s been deployed, just use the Bluemix console.
This post is just a quick introduction and high level overview of how you can use the new code-generation capabilities in Bluemix to generate yourself a Java microservice and deploy it to the cloud. You can do this through the Bluemix console, using the command line, or even just mix and match the two. The choice is yours. Keep an eye out for future articles in which we’ll dive into the Java microservice in more detail, walking you through the actual classes that have been created and how you can use them as a basis for your own services. Finally, just explore and have fun playing with the new features, over time we’ll be adding more patterns, services, and microservices functionality. If you have any questions or suggestions, we’d love to hear them. Hang out with our team on the #cloud-native Slack channel and register at http://ibm.biz/IBMCloudNativeSlack