Create your first Java web app in Azure
The steps in this quickstart show how to use the Eclipse IDE to publish a Java web app to App Service, but you can use the IntelliJ IDEA Ultimate Edition or Community Edition. For more information, see Create a Hello World web app for Azure using IntelliJ.
When you have completed this quickstart, your application will look similar to the following illustration when you view it in a web browser:
To complete this quickstart, install:
- The free Eclipse IDE for Java EE Developers. This quickstart uses Eclipse Neon.
- The Azure Toolkit for Eclipse.
You will need to sign into your Azure account using the Azure Toolkit for Eclipse to complete the steps in this quickstart. To do so, see Azure Sign In Instructions for the Azure Toolkit for Eclipse.
Create a dynamic web project in Eclipse
In Eclipse, select File > New > Dynamic Web Project.
In the New Dynamic Web Project dialog box, name the project MyFirstJavaOnAzureWebApp, and select Finish.
Add a JSP page
If Project Explorer is not displayed, restore it.
In Project Explorer, expand the MyFirstJavaOnAzureWebApp project. Right-click WebContent, and then select New > JSP File.
In the New JSP File dialog box:
- Name the file index.jsp.
In the index.jsp file, replace the
<body></body> element with the following markup:
<body> <h1><% out.println("Hello Azure!"); %></h1> </body>
Save the changes.
If you see an error on line 1 that refers to a missing Java Servlet class, you can ignore it.
Publish the web app to Azure
In Project Explorer, right-click your project, and then select Azure > Publish as Azure Web App.
If you are prompted with the Azure Sign In dialog box, you will need to follow the steps in the Azure Sign In Instructions for the Azure Toolkit for Eclipse article to enter your credentials.
Deploy Web App dialog box
After you have signed in to your Azure account, the Deploy Web App dialog box appears.
Create App Service dialog box
The Create App Service dialog box appears with default values. The number 170602185241 shown in the following image is different in your dialog box.
In the Create App Service dialog box:
- Enter a unique name for your web app, or keep the generated name. This name must be unique across Azure. The name is part of the URL address for the web app. For example: if the web app name is MyJavaWebApp, the URL is myjavawebapp.azurewebsites.net.
- For this quickstart, keep the default web container.
- Select an Azure subscription.
On the App service plan tab:
- Create new: Keep the default, which is the name of the App Service plan.
- Location: Select West Europe or a location near you.
Pricing tier: Select the free option. For features, see App Service pricing.
An App Service plan specifies the location, size, and features of the web server farm that hosts your app. You can save money when hosting multiple apps by configuring the web apps to share a single App Service plan.
App Service plans define:
- Region (for example: North Europe, East US, or Southeast Asia)
- Instance size (small, medium, or large)
- Scale count (1 to 20 instances)
- SKU (Free, Shared, Basic, Standard, or Premium)
Resource group tab
Select the Resource group tab. Keep the default generated value for the resource group.
A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.
The Azure Toolkit creates the web app and displays a progress dialog box.
Deploy Web App dialog box
In the Deploy Web App dialog box, select Deploy to root. If you have an app service at wingtiptoys.azurewebsites.net and you do not deploy to the root, the web app named MyFirstJavaOnAzureWebApp is deployed to wingtiptoys.azurewebsites.net/MyFirstJavaOnAzureWebApp.
The dialog box shows the Azure, JDK, and web container selections.
Select Deploy to publish the web app to Azure.
When the publishing finishes, select the Published link in the Azure Activity Log dialog box.
Congratulations! You have successfully deployed your web app to Azure.
Update the web app
Change the sample JSP code to a different message.
<body> <h1><% out.println("Hello again Azure!"); %></h1> </body>
Save the changes.
In Project Explorer, right-click the project, and then select Azure > Publish as Azure Web App.
The Deploy Web App dialog box appears and shows the app service that you previously created.
Select Deploy to root each time you publish.
Select the web app and select Deploy, which publishes the changes.
When the Publishing link appears, select it to browse to the web app and see the changes.
Manage the web app
Go to the Azure portal to see the web app that you created.
From the left menu, select Resource Groups.
Select the resource group. The page shows the resources that you created in this quickstart.
Select the web app (webapp-170602193915 in the preceding image).
The Overview page appears. This page gives you a view of how the app is doing. Here, you can perform basic management tasks like browse, stop, start, restart, and delete. The tabs on the left side of the page show the different configurations that you can open.
Clean up resources
In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group.
- From your web app's Overview page in the Azure portal, select the myResourceGroup link under Resource group.
- On the resource group page, make sure that the listed resources are the ones you want to delete.
- Select Delete, type myResourceGroup in the text box, and then select Delete.