Build your first Java app
Deploy to cloud
Prerequisites
Before running this sample on Azure, you need to
- 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 - The Azure Command-Line Interface (CLI).
Install Azure CLI 2.0
Create an Azure service principal
- Sign into your Azure account by using the Azure CLI:
az login
Follow the instructions to complete the sign-in process.
- Create an Azure service principal:
az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"
Where
uuuuuuuu
is the user name andpppppppp
is the password for the service principal. - 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
, andtttttttt
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 Mavensettings.xml
file in the next section.
Configure Maven to use your Azure service principal
- 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
-
Add your Azure service principal settings from the previous section of this tutorial to the
<servers>
collection in the settings.xml file; for example:<servers> <server> <id>azure-auth</id> <configuration> <client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client> <tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant> <key>pppppppp</key> <environment>AZURE</environment> </configuration> </server> </servers>
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 theappId
value from your service principal.<tenant>
| Contains thetenant
value from your service principal.<key>
| Contains thepassword
value from your service principal.<environment>
| Defines the target Azure cloud environment, which isAZURE
in this example. (A full list of environments is available in the [Maven Plugin for Azure Web Apps] documentation) - Save and close the settings.xml file.
Build and deploy your web app to Azure
- 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
- 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.
-
When your web has been deployed, you will see a success message from command Line
by pasting the URL to browser, you will see the sample web app running on Cloud!
You will also be able to manage it by using the Azure portal.
-
Your web app will be listed in App Services:
-
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