Skip to content

Commit 14952f9

Browse files
authored
Merge pull request #246471 from cephalin/java
quarkus/tomcat/jboss for java quickstart
2 parents 91da5f4 + 1c79337 commit 14952f9

File tree

6 files changed

+474
-26
lines changed

6 files changed

+474
-26
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+
![Screenshot of Maven Hello World web app running in Azure App Service.](../../media/quickstart-java/jboss-sample-in-app-service.png)
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+
![Screenshot of Maven Hello World web app running in Azure App Service.](../../media/quickstart-java/jboss-sample-in-app-service.png)
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.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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 with an embedded server to [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+
The quickstart uses a [Quarkus](https://quarkus.io) sample, which comes with a bundled web server. You can deploy your own application and server bundle in a single JAR file to App Service instead of the using the Tomcat or JBoss hosting options. If you want, you can also embed a Tomcat server in the JAR file and run that in App Service.
13+
14+
> [!NOTE]
15+
> For Spring apps that requires all the Spring services, try [Azure Spring Apps](../../../spring-apps/quickstart.md) instead. However, you can deploy Spring Boot apps to App Service.
16+
17+
:::image type="content" source="../../media/quickstart-java/quarkus-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Maven Hellow World web app running in Azure App Service in introduction.":::
18+
19+
If Maven isn't your preferred development tool, check out our similar tutorials for Java developers:
20+
+ [Gradle](../../configure-language-java.md?pivots=platform-linux#gradle)
21+
+ [IntelliJ IDEA](/azure/developer/java/toolkit-for-intellij/create-hello-world-web-app)
22+
+ [Eclipse](/azure/developer/java/toolkit-for-eclipse/create-hello-world-web-app)
23+
+ [Visual Studio Code](https://code.visualstudio.com/docs/java/java-webapp)
24+
25+
[!INCLUDE [quickstarts-free-trial-note](../../../../includes/quickstarts-free-trial-note.md)]
26+
27+
## 1 - Use Azure Cloud Shell
28+
29+
[!INCLUDE [cloud-shell-try-it-no-header.md](../../../../includes/cloud-shell-try-it-no-header.md)]
30+
31+
## 2 - Create a Java app
32+
33+
Execute the following Maven command in the Cloud Shell prompt to create a new app named `quarkus-hello-azure`:
34+
35+
```azurecli-interactive
36+
mvn io.quarkus.platform:quarkus-maven-plugin:3.2.2.Final:create \
37+
-DprojectGroupId=org.acme \
38+
-DprojectArtifactId=quarkus-hello-azure \
39+
-Dextensions='resteasy-reactive'
40+
```
41+
42+
Then change your working directory to the project folder:
43+
44+
```azurecli-interactive
45+
cd quarkus-hello-azure
46+
```
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 **1** for Java 17, then **Enter**.
61+
1. For **Define value for pricingTier**, type **9** for P1v2, then **Enter**.
62+
1. For **Confirm**, type **Y**, then **Enter**.
63+
64+
```
65+
Please confirm webapp properties
66+
AppName : quarkus-hello-azure-1690375364238
67+
ResourceGroup : quarkus-hello-azure-1690375364238-rg
68+
Region : centralus
69+
PricingTier : P1v2
70+
OS : Linux
71+
Java Version: Java 17
72+
Web server stack: Java SE
73+
Deploy to slot : false
74+
Confirm (Y/N) [Y]: y
75+
[INFO] Saving configuration to pom.
76+
[INFO] ------------------------------------------------------------------------
77+
[INFO] BUILD SUCCESS
78+
[INFO] ------------------------------------------------------------------------
79+
[INFO] Total time: 8.139 s
80+
[INFO] Finished at: 2023-07-26T12:42:48Z
81+
[INFO] ------------------------------------------------------------------------
82+
```
83+
84+
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.
85+
86+
The relevant portion of the `pom.xml` file should look similar to the following example.
87+
88+
```xml-interactive
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>com.microsoft.azure</groupId>
93+
<artifactId>>azure-webapp-maven-plugin</artifactId>
94+
<version>x.xx.x</version>
95+
<configuration>
96+
<schemaVersion>v2</schemaVersion>
97+
<resourceGroup>your-resourcegroup-name</resourceGroup>
98+
<appName>your-app-name</appName>
99+
...
100+
</configuration>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
```
105+
106+
You can modify the configurations for App Service directly in your `pom.xml`. Some common configurations are listed in the following table:
107+
108+
Property | Required | Description | Version
109+
---|---|---|---
110+
`<schemaVersion>` | false | Specify the version of the configuration schema. Supported values are: `v1`, `v2`. | 1.5.2
111+
`<subscriptionId>` | false | Specify the subscription ID. | 0.1.0+
112+
`<resourceGroup>` | true | Azure Resource Group for your Web App. | 0.1.0+
113+
`<appName>` | true | The name of your Web App. | 0.1.0+
114+
`<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+
115+
`<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+
116+
`<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+
117+
`<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+
118+
119+
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).
120+
121+
Be careful about the values of `<appName>` and `<resourceGroup>` (`quarkus-hello-azure-1690375364238` and `quarkus-hello-azure-1690375364238-rg` accordingly in the demo). They're used later.
122+
123+
## 4 - Deploy the app
124+
125+
With all the configuration ready in your *pom.xml* file, you can deploy your Java app to Azure with one single command.
126+
127+
1. Rebuild the JAR file using the following command:
128+
129+
```bash
130+
mvn clean package -Dquarkus.package.type=uber-jar -D%prod.quarkus.http.port=80
131+
```
132+
133+
This command adds two Quarkus properties:
134+
135+
- `quarkus.package.type=uber-jar` tells Maven to [generate an Uber-Jar](https://quarkus.io/guides/maven-tooling#uber-jar-maven), which includes all dependencies in the JAR file.
136+
- `%prod.quarkus.http.port=80` tells Quarkus to use port 80 for the prod environment at runtime, which is the default port that the Linux Java container uses. If you want, you can change the port number of the Java container with the `WEBSITES_PORT` app setting.
137+
138+
You can configure these properties by using other means, but they're added to `mvn package` command here for simplicity.
139+
140+
2. Deploy to Azure by using the following command:
141+
142+
```bash
143+
mvn azure-webapp:deploy
144+
```
145+
146+
If the deployment succeeds, you see the following output:
147+
148+
```output
149+
[INFO] Successfully deployed the artifact to https://quarkus-hello-azure-1690375364238.azurewebsites.net
150+
[INFO] ------------------------------------------------------------------------
151+
[INFO] BUILD SUCCESS
152+
[INFO] ------------------------------------------------------------------------
153+
[INFO] Total time: 02:20 min
154+
[INFO] Finished at: 2023-07-26T12:47:50Z
155+
[INFO] ------------------------------------------------------------------------
156+
```
157+
158+
Once deployment is completed, your application is ready at `http://<appName>.azurewebsites.net/` (`http://quarkus-hello-azure-1690375364238.azurewebsites.net` in the demo). Open the url with your local web browser, you should see
159+
160+
:::image type="content" source="../../media/quickstart-java/quarkus-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Maven Hellow World web app running in Azure App Service.":::
161+
162+
**Congratulations!** You've deployed your first Java app to App Service.
163+
164+
## 5 - Clean up resources
165+
166+
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:
167+
168+
```azurecli-interactive
169+
az group delete --name <your resource group name; for example: quarkus-hello-azure-1690375364238-rg> --yes
170+
```
171+
172+
This command may take a minute to run.

0 commit comments

Comments
 (0)