Create a cloud native application in 10 minutes or less using IBM’s Developer Tools CLI

Whether you are an experienced developer or just starting your career, creating an app from scratch is never easy. This is especially true when learning a new language. We tend to leverage examples or tutorials as a base and iterate from there. This alone can be daunting, and we have not yet considered testing and deployment of the app yet.

Luckily, IBM’s Cloud Developer Tools CLI can help you overcome these issues. The Cloud Developer Tools CLI is a command line driven tool for creating and deploying applications to IBM Cloud, it provides options to generate code based on 1) pattern and 2) language.

The following patterns are supported:

  • Web application
  • Mobile application
  • Backend for frontend
  • Microservice

Depending on the pattern selected, the following languages are supported:

  • Java
  • Node
  • Python
  • Swift

The tool uses two containers to facilitate building and testing of applications. The first is the tools container, which contains the necessary utilities to build and test your application. The second container is the run container, this container is of a form suitable to be deployed for use to IBM Cloud.

Learning Objectives

In this tutorial we demonstrate how to generate code for a simple Hello, World! web application written in Java that can be deployed to IBM Cloud using the Developer Tools CLI.

Prerequisites

The following prerequisites are required:

  • An IBM Cloud account.
  • Installed and configured IBM Cloud Developer Tools CLI, if not installed, follow the steps in the “Installing” section then the steps in the “Configure Your Environment” section.

Estimated time

This guide should take approximately 1 hour to complete.

Steps

1. Generate code for a Java Web Application

  1. Use the bx dev create command to interactively generate code for a Java web application. Note that the code will generated in the current directory.
bx dev create
  1. For the “pattern” choice, select “Web App”.

  2. For the “starter” choice, select “Basic Web”.

  3. For the “language” choice, select “Java – MicroProfile / Java EE”.

  4. Enter a name for your project, for example, hello-java.

  5. Enter a hostname for your project, for example, hello-java-<username>.

  6. For this tutorial, we will not be adding any services, to reply with an n for the last step.

    IBM_Cloud Developer CLI Java Create

  7. The code will now be generated, look for a success message like the one below:

The project, hello-java, has been successfully saved into the current directory.

OK

2. Inspect the generated code

  1. Use the command line or your favourite IDE to see the generated code structure. In this case we are using Atom to show the code structure.

    Java Project Layout

  2. A few files worth noting are:

  3. src/main/java/application/HealthEndpoint.java: This is the web application entry point.

  4. cli-config.yml: A deployment file which is configured by default to deploy the project as a Cloud Foundry application to IBM Cloud.

  5. chart: A directory where helm charts are generated. Helm charts are Kubernetes deployment templates which are used to help streamline deployments.

  6. manifest.xml: A Cloud Foundry deployment file.

  7. .bluemix: A directory containing templates for interacting with the IBM DevOps services.

  8. Dockerfile and Dockerfile-tools: Docker files which contain the contains for running and debugging the applications, respectively.

3. Build and run the application locally

  1. Use the bx dev build command to build the project, this may take some minutes. The build artificats will be generated in the target directory. Note that it is possible to build the project using commands specific to the language, but we want to mimic the IBM Cloud environment and build process as much as possible, so it’s important to use the Cloud Developer Tools CLI.
bx dev build

Java Project Build

  1. Use the bx dev run command to run the application locally.
bx dev run

Java App Run

This will run the application locally in a Docker container. The URL to the app should be http://localhost:9080/<container-name> where container-name will be shown in the run output. The configuration for the liberty server including the port will be defined in target/liberty-plugin-config.xml. The URI for the application is defined in the war manifest file and the war is generated in the target directory.

A screen shot of the generated Java web app landing page is show below.

Java Hello World App

4. Deploy the application to IBM Cloud

  1. Use the bx dev deploy command to deploy the application to IBM Cloud as a Cloud Foundry application.
bx dev deploy

To see the application in your IBM Cloud dashboard, go to the main dashboard view, the application will be listed under the “Cloud Foundry App” group. Clicking the app URL will open the Java web app on a new tab.

Java CF App

Summary

We hope this provided a good start on how to generate, run locally, and deploy apps quickly. Do consider using IBM Cloud and the IBM Cloud Developer Tools CLI for your next project!