|
| 1 | +--- |
| 2 | +author: cephalin |
| 3 | +ms.service: app-service |
| 4 | +ms.devlang: java |
| 5 | +ms.topic: include |
| 6 | +ms.date: 08/30/2023 |
| 7 | +ms.author: cephalin |
| 8 | +--- |
| 9 | + |
| 10 | +In this quickstart, you'll use the [Maven Plugin for Azure App Service Web Apps](https://github.com/microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md) to deploy a Java web application to a Linux JBoss EAP server in [Azure App Service](/azure/app-service/). App Service provides a highly scalable, self-patching web app hosting service. Use the tabs to switch between Tomcat, JBoss, or embedded server (Java SE) instructions. |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +If Maven isn't your preferred development tool, check out our similar tutorials for Java developers: |
| 15 | ++ [Gradle](../../configure-language-java.md?pivots=platform-linux#gradle) |
| 16 | ++ [IntelliJ IDEA](/azure/developer/java/toolkit-for-intellij/create-hello-world-web-app) |
| 17 | ++ [Eclipse](/azure/developer/java/toolkit-for-eclipse/create-hello-world-web-app) |
| 18 | ++ [Visual Studio Code](https://code.visualstudio.com/docs/java/java-webapp) |
| 19 | + |
| 20 | +[!INCLUDE [quickstarts-free-trial-note](../../../../includes/quickstarts-free-trial-note.md)] |
| 21 | + |
| 22 | +## 1 - Use Azure Cloud Shell |
| 23 | + |
| 24 | +[!INCLUDE [cloud-shell-try-it-no-header.md](../../../../includes/cloud-shell-try-it-no-header.md)] |
| 25 | + |
| 26 | +## 2 - Create a Java app |
| 27 | + |
| 28 | +Clone the Pet Store demo application. |
| 29 | + |
| 30 | +```azurecli-interactive |
| 31 | +git clone https://github.com/Azure-Samples/app-service-java-quickstart |
| 32 | +``` |
| 33 | + |
| 34 | +Change directory to the completed pet store project and build it. |
| 35 | + |
| 36 | +> [!TIP] |
| 37 | +> The `petstore-ee7` sample requires **Java 11 or newer**. The `booty-duke-app-service` sample project requires **Java 17**. If your installed version of Java is less than 17, run the build from within the `petstore-ee7` directory, rather than at the top level. |
| 38 | +
|
| 39 | +```azurecli-interactive |
| 40 | +cd app-service-java-quickstart |
| 41 | +git checkout 20230308 |
| 42 | +cd petstore-ee7 |
| 43 | +mvn clean install |
| 44 | +``` |
| 45 | + |
| 46 | +If you see a message about being in **detached HEAD** state, this message is safe to ignore. Because you won't make any Git commit in this quickstart, detached HEAD state is appropriate. |
| 47 | + |
| 48 | +## 3 - Configure the Maven plugin |
| 49 | + |
| 50 | +The deployment process to Azure App Service uses your Azure credentials from the Azure CLI automatically. If the Azure CLI isn't installed locally, then the Maven plugin authenticates with OAuth or device sign-in. For more information, see [authentication with Maven plugins](https://github.com/microsoft/azure-maven-plugins/wiki/Authentication). |
| 51 | + |
| 52 | +Run the Maven command shown next to configure the deployment. This command helps you to set up the App Service operating system, Java version, and Tomcat version. |
| 53 | + |
| 54 | +```azurecli-interactive |
| 55 | +mvn com.microsoft.azure:azure-webapp-maven-plugin:2.12.0:config |
| 56 | +``` |
| 57 | + |
| 58 | +1. For **Create new run configuration**, type **Y**, then **Enter**. |
| 59 | +1. For **Define value for OS**, type **2** for Linux, then **Enter**. |
| 60 | +1. For **Define value for javaVersion**, type **2** for Java 11, then **Enter**. |
| 61 | +1. For **webContainer** option, type **1** for Jbosseap 7, then **Enter**. |
| 62 | +1. For **Define value for pricingTier**, type **1** for P1v3, then **Enter**. |
| 63 | +1. For **Confirm**, type **Y**, then **Enter**. |
| 64 | + |
| 65 | + ``` |
| 66 | + Please confirm webapp properties |
| 67 | + AppName : petstoreee7-1690443003536 |
| 68 | + ResourceGroup : petstoreee7-1690443003536-rg |
| 69 | + Region : centralus |
| 70 | + PricingTier : P1v3 |
| 71 | + OS : Linux |
| 72 | + Java Version: Java 11 |
| 73 | + Web server stack: Jbosseap 7 |
| 74 | + Deploy to slot : false |
| 75 | + Confirm (Y/N) [Y]: |
| 76 | + [INFO] Saving configuration to pom. |
| 77 | + [INFO] ------------------------------------------------------------------------ |
| 78 | + [INFO] BUILD SUCCESS |
| 79 | + [INFO] ------------------------------------------------------------------------ |
| 80 | + [INFO] Total time: 19.914 s |
| 81 | + [INFO] Finished at: 2023-07-27T07:30:20Z |
| 82 | + [INFO] ------------------------------------------------------------------------ |
| 83 | + ``` |
| 84 | +
|
| 85 | +After you've confirmed your choices, the plugin adds the above plugin element and requisite settings to your project's `pom.xml` file that configure your web app to run in Azure App Service. |
| 86 | +
|
| 87 | +The relevant portion of the `pom.xml` file should look similar to the following example. |
| 88 | +
|
| 89 | +```xml-interactive |
| 90 | +<build> |
| 91 | + <plugins> |
| 92 | + <plugin> |
| 93 | + <groupId>com.microsoft.azure</groupId> |
| 94 | + <artifactId>>azure-webapp-maven-plugin</artifactId> |
| 95 | + <version>x.xx.x</version> |
| 96 | + <configuration> |
| 97 | + <schemaVersion>v2</schemaVersion> |
| 98 | + <resourceGroup>your-resourcegroup-name</resourceGroup> |
| 99 | + <appName>your-app-name</appName> |
| 100 | + ... |
| 101 | + </configuration> |
| 102 | + </plugin> |
| 103 | + </plugins> |
| 104 | +</build> |
| 105 | +``` |
| 106 | + |
| 107 | +You can modify the configurations for App Service directly in your `pom.xml`. Some common configurations are listed in the following table: |
| 108 | + |
| 109 | +Property | Required | Description | Version |
| 110 | +---|---|---|--- |
| 111 | +`<schemaVersion>` | false | Specify the version of the configuration schema. Supported values are: `v1`, `v2`. | 1.5.2 |
| 112 | +`<subscriptionId>` | false | Specify the subscription ID. | 0.1.0+ |
| 113 | +`<resourceGroup>` | true | Azure Resource Group for your Web App. | 0.1.0+ |
| 114 | +`<appName>` | true | The name of your Web App. | 0.1.0+ |
| 115 | +`<region>` | false | Specifies the region to host your Web App; the default value is **centralus**. All valid regions at [Supported Regions](https://azure.microsoft.com/global-infrastructure/services/?products=app-service) section. | 0.1.0+ |
| 116 | +`<pricingTier>` | false | The pricing tier for your Web App. The default value is **P1v2** for production workload, while **B2** is the recommended minimum for Java dev/test. For more information, see [App Service Pricing](https://azure.microsoft.com/pricing/details/app-service/linux/)| 0.1.0+ |
| 117 | +`<runtime>` | false | The runtime environment configuration. For more information, see [Configuration Details](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App:-Configuration-Details). | 0.1.0+ |
| 118 | +`<deployment>` | false | The deployment configuration. For more information, see [Configuration Details](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App:-Configuration-Details). | 0.1.0+ |
| 119 | + |
| 120 | +For the complete list of configurations, see the plugin reference documentation. All the Azure Maven Plugins share a common set of configurations. For these configurations see [Common Configurations](https://github.com/microsoft/azure-maven-plugins/wiki/Common-Configuration). For configurations specific to App Service, see [Azure Web App: Configuration Details](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App:-Configuration-Details). |
| 121 | + |
| 122 | +Be careful about the values of `<appName>` and `<resourceGroup>` (`petstoreee7-1690443003536` and `petstoreee7-1690443003536-rg` accordingly in the demo). They're used later. |
| 123 | + |
| 124 | +## 4 - Deploy the app |
| 125 | + |
| 126 | +With all the configuration ready in your *pom.xml* file, you can deploy your Java app to Azure with one single command. |
| 127 | + |
| 128 | +```azurecli-interactive |
| 129 | +# Disable testing, as it requires Wildfly to be installed locally. |
| 130 | +mvn package azure-webapp:deploy -DskipTests |
| 131 | +``` |
| 132 | + |
| 133 | +Once deployment is completed, your application is ready at `http://<appName>.azurewebsites.net/` (`http://petstoreee7-1690443003536.azurewebsites.net` in the demo). Open the url with your local web browser, you should see |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +**Congratulations!** You've deployed your first Java app to App Service. |
| 138 | + |
| 139 | +## 5 - Clean up resources |
| 140 | + |
| 141 | +In the preceding steps, you created Azure resources in a resource group. If you don't need the resources in the future, delete the resource group from portal, or by running the following command in the Cloud Shell: |
| 142 | + |
| 143 | +```azurecli-interactive |
| 144 | +az group delete --name <your resource group name; for example: petstoreee7-1690443003536-rg> --yes |
| 145 | +``` |
| 146 | + |
| 147 | +This command may take a minute to run. |
0 commit comments