Using CLI to create, build, and manage MobileFirst project artifacts
Topics covered in this tutorial:
- Installation of the Command Line Interface (CLI)
- Creating MobileFirst projects and native API
- Creating hybrid applications
- Creating test servers and the build-and-deploy flow
- Creating and testing adapters
- Using the Export command
- Importing CLI-generated projects into MobileFirst Studio
Installation of the Command Line Interface (CLI)
To get the CLI installer, follow through this page first.
- Extract the mobilefirst-cli-installer-6.3.zip archive and navigate to the mobilefirst-cli-installer-6.3 folder.
- Select the appropriate installer for your operating system and run it.
- Click the Install icon to begin the installation.
- Accept the Software License Agreement.
- Select the installation folder.
- Accept the Pre-Installation Summary by clicking Install and then select Done when installation is complete.
Creating MobileFirst projects and native API
The CLI installer adds the installation folder to your
path, so that IBM MobileFirst Platform CLI commands can be run from any directory.
Create a MobileFirst project from the CLI by using either of these commands:
mobilefirst create projectName, or
mfp create projectName
mobilefirst help – Shows all command usage:
mobilefirst info - Gives OS release, system memory, node.js version, IBM MobileFirst CLI version
You can use the interactive or direct options to add native API. First navigate to the MobileFirst project directory.
mobilefirst add api
mobilefirst add api --environment ios apiName, or
-e for environment
Example: (direct mode)
Creating hybrid applications
Add a hybrid application from the CLI
mobilefirst add hybrid [ – Creates a new hybrid application, which is generated into the /apps folder of the current project.
mobilefirst add environment – Adds an environment to your application. Can be used in the project directory if the project only contains one app. Otherwise, select which app to add the environment to, or call the command from inside the directory of the hybrid app the environment should be added to.
Interactive mode allows you to select one or more environments to add.
To add environments in direct mode:
To add an application skin from the CLI, use these commands:
mobilefirst add skin – Interactive mode prompts for the platform to target and name. The current working directory must be under an existing hybrid application, and at least one environment must already be added to this app.
mfp add skin [--environment|-e android|blackberry|blackberry10|iphone|ipad skin-name]
To add optional features to a hybrid application from the CLI, use these commands:
mobilefirst add feature – Interactive mode prompts for the features to add.
To remove optional features from a hybrid application by using the CLI, use these commands:
mobilefirst remove feature – Interactive mode prompts for the features to remove.
mobilefirst remove feature [fips|jsonstore|tealeaf] – direct mode
BYOE - Bring Your Own Editor: Use your favorite text editor or IDE to develop from CLI
Creating test servers and the build-and-deploy flow
The instance of the Liberty development server is created on the default user directory. For example:
mfp start - Starts the server. If the project is not deployed, this command runs the build-all-and deploy flow.
mfp stop - Stops the server.
mfp run - Verbose server mode that outputs server events to console or log.
mfp status - Gives the status of the server.
mfp build - Builds the project. When you are not in the root directory of the project, this command builds the current directory and subdirectories.
mfp deploy - Deploys anything that you built in the root directory of the project. The server will be automatically created and started as needed. When you are in the adapter folder, this command deploys that adapter.
mfp bd - Builds and deploys (a combination of both commands in a single command).
mfp preview [environments-name --noshell|-n] - Displays a preview of the current application or environment in your default browser.
mfp restart - Restarts the local test server.
mfp console - Opens the MobileFirst Console in your default web browser.
Creating and testing adapters
mfp add adapter - interactive mode
mfp add adapter --type http myAdapterName, or
-t for type. The types of adapters that can be added are HTTP, SQL, Cast Iron, SAP Netweaver Gateway, and JMS.
mfp invoke - interactive mode
After a procedure is selected, you are prompted to enter parameters:
mfp invoke adapterName:function [parameter1[,parameter2...]] - direct mode
Using the Export command
Interactive Mode project export
By using the
export command, you can create a compressed file, which contains the entire MobileFirst project, or the optimized hybrid assets to use in a native application.
mfp export - Running this command in the project root folder prompts you to enter the path and name of the compressed file to export to.
The resulting compressed file is intended to be shared with other MobileFirst developers. The compressed file contains source artifacts and everything another developer would need to build the missing artifacts.
Direct Mode project export
mfp export [ - If run from the root folder of the project, direct mode takes one additional argument, which is the full path to the compressed file to create.
Interactive Mode hybrid export
First make sure that the app is built by using the
mfp build command.
Run the hybrid asset export within the environment folder of the existing hybrid app. Interactive mode asks whether to include the native libraries, the path, and file name of the compressed file to export to.
The native libraries are built files, which native application IDEs need to ensure the hybrid assets can be used in a native app.
Direct Mode hybrid export
mfp export [path to zip file] [-i | --includeNativeLibs] - In direct mode, provide the full path to export hybrid assets. If the arguments
--includeNativeLibs are supplied, the native libraries are included.
Importing CLI-generated projects into MobileFirst Platform Studio
From Eclipse, select File > Import > Existing Projects into Workspace.
CLI can also open an existing MobileFirst Studio Eclipse project. Using the command line, navigate to a workspace that was created by Eclipse.
For more information about the Command Line Interface, see the IBM MobileFirst Platform Foundation user documentation.