Build your first Java app

Deploy to cloud


Before running this sample on Azure, you need to

  1. Have an Azure subscription; if you don’t already have one, you can sign up for a free Azure account.
    Create your free Azure account
  2. The Azure Command-Line Interface (CLI).
    Install Azure CLI 2.0

Create an Azure service principal

  1. Sign into your Azure account by using the Azure CLI:
    az login

    Follow the instructions to complete the sign-in process.

  2. Create an Azure service principal:
    az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"

    Where uuuuuuuu is the user name and pppppppp is the password for the service principal.

  3. Azure responds with JSON that resembles the following example:
       "appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
       "displayName": "uuuuuuuu",
       "name": "http://uuuuuuuu",
       "password": "pppppppp",
       "tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"

    You will use the values from this JSON response when you configure the Maven plugin to deploy your web app to Azure. The aaaaaaaa, uuuuuuuu, pppppppp, and tttttttt are placeholder values, which are used in this example to make it easier to map these values to their respective elements when you configure your Maven settings.xml file in the next section.

Configure Maven to use your Azure service principal

  1. Open your Maven settings.xml file in a text editor; There are two locations where a settings.xml file may live:
    • The Maven install: ${maven.home}/conf/settings.xml
    • A user’s install: ${user.home}/.m2/settings.xml Below are some examples:
    • Windows: %ProgramFiles%\apache-maven\3.5.0\conf\settings.xml
    • Mac installed by Homebrew: /usr/local/Cellar/maven/3.5.0/libexec/conf
  2. Add your Azure service principal settings from the previous section of this tutorial to the <servers> collection in the settings.xml file; for example:


    Where: Element | Description —|—|— <id> | Specifies a unique name which Maven uses to look up your security settings when you deploy your web app to Azure. <client> | Contains the appId value from your service principal. <tenant> | Contains the tenant value from your service principal. <key> | Contains the password value from your service principal. <environment> | Defines the target Azure cloud environment, which is AZURE in this example. (A full list of environments is available in the [Maven Plugin for Azure Web Apps] documentation)

  3. Save and close the settings.xml file.

Build and deploy your web app to Azure

  1. From the command prompt or terminal window that you were using earlier, rebuild the JAR file using Maven if you made any changes to the pom.xml file; for example:
    mvn clean package
  2. Deploy your web app to Azure by using Maven; for example:
    mvn azure-webapp:deploy

Maven will deploy your web app to Azure; if the web app does not already exist, it will be created.

  1. When your web has been deployed, you will see a success message from command Line

    Deploy Success by pasting the URL to browser, you will see the sample web app running on Cloud!

    Greeting Cloud You will also be able to manage it by using the Azure portal.

  2. Your web app will be listed in App Services:

    App Service View

  3. And the URL for your web app will be listed in the Overview for your web app:


I ran into an issue I have run my app on cloud