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
Depending on the pattern selected, the following languages are supported:
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.
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.
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.
This guide should take approximately 1 hour to complete.
1. Generate code for a Java Web Application
- Use the
bx dev createcommand to interactively generate code for a Java web application. Note that the code will generated in the current directory.
bx dev create
For the “pattern” choice, select “Web App”.
For the “starter” choice, select “Basic Web”.
For the “language” choice, select “Java – MicroProfile / Java EE”.
Enter a name for your project, for example,
Enter a hostname for your project, for example,
For this tutorial, we will not be adding any services, to reply with an
nfor the last step.
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
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.
A few files worth noting are:
src/main/java/application/HealthEndpoint.java: This is the web application entry point.
cli-config.yml: A deployment file which is configured by default to deploy the project as a Cloud Foundry application to IBM Cloud.
chart: A directory where helm charts are generated. Helm charts are Kubernetes deployment templates which are used to help streamline deployments.
manifest.xml: A Cloud Foundry deployment file.
.bluemix: A directory containing templates for interacting with the IBM DevOps services.
Dockerfile-tools: Docker files which contain the contains for running and debugging the applications, respectively.
3. Build and run the application locally
- Use the
bx dev buildcommand to build the project, this may take some minutes. The build artificats will be generated in the
targetdirectory. 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
- Use the
bx dev runcommand to run the application locally.
bx dev run
This will run the application locally in a Docker container. The URL to the app should be
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
A screen shot of the generated Java web app landing page is show below.
4. Deploy the application to IBM Cloud
- Use the
bx dev deploycommand 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.
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!