|
| 1 | +--- |
| 2 | +author: cephalin |
| 3 | +ms.service: app-service |
| 4 | +ms.devlang: java |
| 5 | +ms.topic: quickstart |
| 6 | +ms.date: 06/30/2022 |
| 7 | +ms.author: cephalin |
| 8 | +--- |
| 9 | + |
| 10 | +[Azure App Service](../../overview.md) provides a highly scalable, self-patching web hosting service. This quickstart tutorial shows how to deploy a Java SE app to Azure App Service on Linux using the Azure portal. To follow a quickstart that deploys to Tomcat or JBoss EAP, select one of the Maven options above. |
| 11 | + |
| 12 | +This quickstart configures an App Service app in the **Free** tier and incurs no cost for your Azure subscription. |
| 13 | + |
| 14 | +This quickstart shows you how to make these changes within your browser, without having to install the development environment tools on your machine. |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +You can follow the steps here using a Mac, Windows, or Linux machine. Once the prerequisites are installed, it takes about five minutes to complete the steps. |
| 19 | + |
| 20 | +To complete this quickstart you need: |
| 21 | + |
| 22 | +1. An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?utm_source=campaign&utm_campaign=visual-studio-code-tutorial-app-service-extension&mktingSource=visual-studio-code-tutorial-app-service-extension). |
| 23 | +1. A GitHub account to fork a repository. |
| 24 | + |
| 25 | +## 1 - Fork the sample repository |
| 26 | + |
| 27 | +1. In your browser, navigate to the repository containing [the sample code](https://github.com/Azure-Samples/java-docs-spring-hello-world). |
| 28 | + |
| 29 | +1. In the upper right corner, select **Fork**. |
| 30 | + |
| 31 | +  |
| 32 | + |
| 33 | +1. On the **Create a new fork** screen, confirm the **Owner** and **Repository name** fields. Select **Create fork**. |
| 34 | + |
| 35 | +  |
| 36 | + |
| 37 | + >[!NOTE] |
| 38 | + > This should take you to the new fork. Your fork URL will look something like this: https://github.com/YOUR_GITHUB_ACCOUNT_NAME/java-docs-spring-hello-world |
| 39 | +
|
| 40 | +## 2 - Deploy to Azure |
| 41 | + |
| 42 | +1. Log in to the Azure portal. |
| 43 | + |
| 44 | +1. Type **app services** in the search. Under **Services**, select **App Services**. |
| 45 | + |
| 46 | +  |
| 47 | + |
| 48 | + |
| 49 | +1. In the **App Services** page, select **Create**. |
| 50 | + |
| 51 | +  |
| 52 | + |
| 53 | +1. Fill out the **Create Web App** page as follows. |
| 54 | + - **Resource Group**: Create a resource group named _myResourceGroup_. |
| 55 | + - **Name**: Type a globally unique name for your web app. |
| 56 | + - **Publish**: Select _Code_. |
| 57 | + - **Runtime stack**: Select _Java 11_. |
| 58 | + - **Java web-server stack**: Select _Java SE (Embedded Web Server)_. |
| 59 | + - **Operating system**: Select _Linux_. |
| 60 | + - **Region**: Select an Azure region close to you. |
| 61 | + - **App Service Plan**: Create an app service plan named _myAppServicePlan_. |
| 62 | + |
| 63 | +1. To change to the Free tier, next to **Sku and size**, select **Change size**. |
| 64 | + |
| 65 | +1. In the Spec Picker, select **Dev/Test** tab, select **F1**, and select the **Apply** button at the bottom of the page. |
| 66 | + |
| 67 | +  |
| 68 | + |
| 69 | +1. Select the **Review + create** button at the bottom of the page. |
| 70 | + |
| 71 | +1. After validation runs, select the **Create** button at the bottom of the page. This will create an Azure resource group, app service plan, and app service. |
| 72 | + |
| 73 | +1. After the Azure resources are created, select **Go to resource**. |
| 74 | + |
| 75 | +1. From the left navigation, select **Deployment Center**. |
| 76 | + |
| 77 | +  |
| 78 | + |
| 79 | +1. Under **Settings**, select a **Source**. For this quickstart, select _GitHub_. |
| 80 | + |
| 81 | +1. In the section under **GitHub**, select the following settings: |
| 82 | + - Organization: Select your organization. |
| 83 | + - Repository: Select _java-docs-spring-hello-world_. |
| 84 | + - Branch: Select _main_. |
| 85 | + |
| 86 | +1. Select **Save**. |
| 87 | + |
| 88 | +  |
| 89 | + |
| 90 | +> [!TIP] |
| 91 | +> This quickstart uses GitHub. Additional continuous deployment sources include Bitbucket, Local Git, Azure Repos, and External Git. FTPS is also a supported deployment method. |
| 92 | + |
| 93 | +1. Once the GitHub integration is saved, select **Overview** > **URL**. |
| 94 | + |
| 95 | +  |
| 96 | + |
| 97 | +The Java sample code is running in an Azure App Service Linux web app. |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +**Congratulations!** You've deployed your first Java app to App Service using the Azure portal. |
| 102 | + |
| 103 | +## 3 - Update in GitHub and redeploy the code |
| 104 | + |
| 105 | +1. Browse to your GitHub fork of java-docs-spring-hello-world. |
| 106 | + |
| 107 | +1. On your repo page, press `.` to start Visual Studio code within your browser. |
| 108 | + |
| 109 | + > [!NOTE] |
| 110 | + > The URL will change from GitHub.com to GitHub.dev. This feature only works with repos that have files. This does not work on empty repos. |
| 111 | +
|
| 112 | +  |
| 113 | + |
| 114 | +1. Navigate to **src/main/java/com/example/demo/DemoApplication.java**. |
| 115 | + |
| 116 | +  |
| 117 | + |
| 118 | +1. Edit the **sayHello** method so that it shows "Hello Azure!" instead of "Hello World!" |
| 119 | + |
| 120 | + ```java |
| 121 | + @RequestMapping("/") |
| 122 | + String sayHello() { |
| 123 | + return "Hello Azure!"; |
| 124 | + } |
| 125 | + ``` |
| 126 | + |
| 127 | +1. From the **Source Control** menu, select the **Stage Changes** button to stage the change. |
| 128 | + |
| 129 | +  |
| 130 | + |
| 131 | +1. Enter a commit message such as `Hello Azure`. Then, select **Commit and Push**. |
| 132 | + |
| 133 | +  |
| 134 | + |
| 135 | +1. Once deployment has completed, return to the browser window that opened during the **Browse to the app** step, and refresh the page. |
| 136 | + |
| 137 | +  |
| 138 | + |
| 139 | +## 4 - Manage your new Azure app |
| 140 | + |
| 141 | +1. Go to the [Azure portal](https://portal.azure.com) to manage the web app you created. Search for and select **App Services**. |
| 142 | + |
| 143 | +  |
| 144 | + |
| 145 | +1. Select the name of your Azure app. |
| 146 | + |
| 147 | +  |
| 148 | + |
| 149 | +Your web app's **Overview** page will be displayed. Here, you can perform basic management tasks like **Browse**, **Stop**, **Restart**, and **Delete**. |
| 150 | +
|
| 151 | + |
| 152 | +
|
| 153 | +The web app menu provides different options for configuring your app. |
| 154 | +
|
| 155 | +## 5 - Clean up resources |
| 156 | +
|
| 157 | +When you're finished with the sample app, you can remove all of the resources for the app from Azure. It will not incur extra charges and keep your Azure subscription uncluttered. Removing the resource group also removes all resources in the resource group and is the fastest way to remove all Azure resources for your app. |
| 158 | + |
| 159 | +1. From your App Service **Overview** page, select the resource group you created earlier. |
| 160 | + |
| 161 | +1. From the resource group page, select **Delete resource group**. Confirm the name of the resource group to finish deleting the resources. |
0 commit comments