Skip to content

Commit 0f38a26

Browse files
Merge pull request #265087 from cephalin/java-quickstart
add spring boot and tomcat embedded pivots
2 parents 1fe2e8e + 54d5b13 commit 0f38a26

File tree

5 files changed

+121
-34
lines changed

5 files changed

+121
-34
lines changed

articles/app-service/includes/quickstart-java/quickstart-java-quarkus.md renamed to articles/app-service/includes/quickstart-java/quickstart-java-javase.md

Lines changed: 116 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ author: cephalin
33
ms.service: app-service
44
ms.devlang: java
55
ms.topic: include
6-
ms.date: 08/30/2023
6+
ms.date: 02/10/2024
77
ms.author: cephalin
88
---
99

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.
10+
In this quickstart, you 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.
1111

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.
12+
The quickstart deploys either a Spring Boot app, embedded Tomcat, or Quarkus app using the [azure-webapp-maven-plugin](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App) plugin.
1313

1414
> [!NOTE]
15-
> For Spring apps that requires all the Spring services, try [Azure Spring Apps](../../../spring-apps/enterprise/quickstart.md) instead. However, you can deploy Spring Boot apps to App Service.
15+
> App Service can host Spring apps. For Spring apps that require all the Spring services, try [Azure Spring Apps](../../../spring-apps/quickstart.md) instead.
1616
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.":::
17+
### [Spring Boot](#tab/springboot)
18+
19+
:::image type="content" source="../../media/quickstart-java/springboot-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Spring Boot Hello World web app running in Azure App Service in introduction.":::
20+
21+
### [Embedded Tomcat](#tab/embeddedtomcat)
22+
23+
:::image type="content" source="../../media/quickstart-java/embedded-tomcat-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of embedded Tomcat Hello World web app running in Azure App Service in introduction.":::
24+
25+
### [Quarkus](#tab/quarkus)
26+
27+
:::image type="content" source="../../media/quickstart-java/quarkus-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Quarkus Hello World web app running in Azure App Service in introduction.":::
28+
29+
-----
1830

1931
If Maven isn't your preferred development tool, check out our similar tutorials for Java developers:
2032
+ [Gradle](../../configure-language-java.md?pivots=platform-linux#gradle)
@@ -28,22 +40,56 @@ If Maven isn't your preferred development tool, check out our similar tutorials
2840

2941
[!INCLUDE [cloud-shell-try-it-no-header.md](../../../../includes/cloud-shell-try-it-no-header.md)]
3042

31-
## 2 - Create a Java app
43+
## 2 - Get the sample app
3244

33-
Execute the following Maven command in the Cloud Shell prompt to create a new app named `quarkus-hello-azure`:
45+
### [Spring Boot](#tab/springboot)
3446

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-
```
47+
1. Download and extract the [default Spring Boot web application template](https://github.com/rd-1-2022/rest-service). This repository is cloned for you when you run the [Spring CLI](https://docs.spring.io/spring-cli/reference/creating-new-projects.html) command `spring boot new my-webapp`.
4148

42-
Then change your working directory to the project folder:
49+
```bash
50+
git clone https://github.com/rd-1-2022/rest-service my-webapp
51+
```
4352

44-
```azurecli-interactive
45-
cd quarkus-hello-azure
46-
```
53+
1. Change your working directory to the project folder:
54+
55+
```azurecli-interactive
56+
cd my-webapp
57+
```
58+
59+
### [Embedded Tomcat](#tab/embeddedtomcat)
60+
61+
1. Download and extract the [embeddedTomcatExample](https://github.com/Azure-Samples/java-docs-embedded-tomcat) repository, or clone it locally by running `git clone`:
62+
63+
```bash
64+
git clone https://github.com/Azure-Samples/java-docs-embedded-tomcat
65+
```
66+
67+
1. Change your working directory to the project folder:
68+
69+
```azurecli-interactive
70+
cd java-docs-embedded-tomcat
71+
```
72+
73+
The application is run using the standard [Tomcat](https://tomcat.apache.org/tomcat-9.0-doc/api/org/apache/catalina/startup/Tomcat.html) class (see [Main.java](https://github.com/Azure-Samples/java-docs-embedded-tomcat/blob/main/src/main/java/com/microsoft/azure/appservice/examples/embeddedtomcat/Main.java) in the sample).
74+
75+
### [Quarkus](#tab/quarkus)
76+
77+
1. Generate a new Quarkus app named `quarkus-hello-azure` with the following Maven command:
78+
79+
```azurecli-interactive
80+
mvn io.quarkus.platform:quarkus-maven-plugin:3.2.2.Final:create \
81+
-DprojectGroupId=org.acme \
82+
-DprojectArtifactId=quarkus-hello-azure \
83+
-Dextensions='resteasy-reactive'
84+
```
85+
86+
1. Change your working directory to the project folder:
87+
88+
```azurecli-interactive
89+
cd quarkus-hello-azure
90+
```
91+
92+
-----
4793

4894
## 3 - Configure the Maven plugin
4995

@@ -52,7 +98,7 @@ The deployment process to Azure App Service uses your Azure credentials from the
5298
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.
5399
54100
```azurecli-interactive
55-
mvn com.microsoft.azure:azure-webapp-maven-plugin:2.12.0:config
101+
mvn com.microsoft.azure:azure-webapp-maven-plugin:2.13.0:config
56102
```
57103
58104
1. For **Create new run configuration**, type **Y**, then **Enter**.
@@ -63,8 +109,8 @@ mvn com.microsoft.azure:azure-webapp-maven-plugin:2.12.0:config
63109
64110
```
65111
Please confirm webapp properties
66-
AppName : quarkus-hello-azure-1690375364238
67-
ResourceGroup : quarkus-hello-azure-1690375364238-rg
112+
AppName : <generated-app-name>
113+
ResourceGroup : <generated-app-name>-rg
68114
Region : centralus
69115
PricingTier : P1v2
70116
OS : Linux
@@ -81,7 +127,7 @@ mvn com.microsoft.azure:azure-webapp-maven-plugin:2.12.0:config
81127
[INFO] ------------------------------------------------------------------------
82128
```
83129
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.
130+
After you confirm 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.
85131

86132
The relevant portion of the `pom.xml` file should look similar to the following example.
87133

@@ -118,13 +164,36 @@ Property | Required | Description | Version
118164

119165
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).
120166

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.
167+
Be careful about the values of `<appName>` and `<resourceGroup>`. They're used later.
122168
123169
## 4 - Deploy the app
124170
125-
With all the configuration ready in your *pom.xml* file, you can deploy your Java app to Azure with one single command.
171+
With all the configuration ready in your [pom.xml](https://github.com/Azure-Samples/java-docs-embedded-tomcat/blob/main/pom.xml) file, you can deploy your Java app to Azure with one single command.
172+
173+
1. Build the JAR file using the following command:
174+
175+
### [Spring Boot](#tab/springboot)
176+
177+
```bash
178+
mvn clean package
179+
```
180+
181+
### [Embedded Tomcat](#tab/embeddedtomcat)
182+
183+
```bash
184+
mvn clean package
185+
```
186+
187+
To make the application it deployable using [azure-webapp-maven-plugin](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App), and running on Azure App Service, the sample configures the `package` goal as follows:
188+
189+
- Build a single uber JAR file, which contains everything the application needs to run.
190+
- Create an [executable JAR](https://en.wikipedia.org/wiki/JAR_(file_format)#Executable_JAR_files) by specifying the Tomcat class as the start-up class.
191+
- Replace the original artifact with the uber JAR to ensure that the deploy step deploys the right file.
126192
127-
1. Rebuild the JAR file using the following command:
193+
> [!TIP]
194+
> Quarkus and Spring Boot both produce two JAR files with `mvn clean package`, but `azure-webapp-maven-plugin` picks the right JAR file to deploy automatically.
195+
196+
### [Quarkus](#tab/quarkus)
128197
129198
```bash
130199
mvn clean package -Dquarkus.package.type=uber-jar -D%prod.quarkus.http.port=80
@@ -137,6 +206,8 @@ With all the configuration ready in your *pom.xml* file, you can deploy your Jav
137206
138207
You can configure these properties by using other means, but they're added to `mvn package` command here for simplicity.
139208

209+
-----
210+
140211
2. Deploy to Azure by using the following command:
141212

142213
```bash
@@ -146,7 +217,7 @@ With all the configuration ready in your *pom.xml* file, you can deploy your Jav
146217
If the deployment succeeds, you see the following output:
147218

148219
```output
149-
[INFO] Successfully deployed the artifact to https://quarkus-hello-azure-1690375364238.azurewebsites.net
220+
[INFO] Successfully deployed the artifact to https://<app-name>.azurewebsites.net
150221
[INFO] ------------------------------------------------------------------------
151222
[INFO] BUILD SUCCESS
152223
[INFO] ------------------------------------------------------------------------
@@ -155,11 +226,27 @@ With all the configuration ready in your *pom.xml* file, you can deploy your Jav
155226
[INFO] ------------------------------------------------------------------------
156227
```
157228

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
229+
### [Spring Boot](#tab/springboot)
230+
231+
Once deployment is completed, your application is ready at `http://<appName>.azurewebsites.net/`. Open the URL `http://<appName>.azurewebsites.net/greeting` with your local web browser (note the `/greeting` path), and you should see:
232+
233+
:::image type="content" source="../../media/quickstart-java/springboot-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Spring Boot Hello World web app running in Azure App Service.":::
234+
235+
### [Embedded Tomcat](#tab/embeddedtomcat)
236+
237+
Once deployment is completed, your application is ready at `http://<appName>.azurewebsites.net/`. Open the url with your local web browser, and you should see:
238+
239+
:::image type="content" source="../../media/quickstart-java/embedded-tomcat-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of embedded Tomcat web app running in Azure App Service.":::
240+
241+
### [Quarkus](#tab/quarkus)
242+
243+
Once deployment is completed, your application is ready at `http://<appName>.azurewebsites.net/`. Open the url with your local web browser, and you should see:
244+
245+
:::image type="content" source="../../media/quickstart-java/quarkus-hello-world-in-browser-azure-app-service.png" alt-text="Screenshot of Quarkus web app running in Azure App Service.":::
159246

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.":::
247+
-----
161248

162-
**Congratulations!** You've deployed your first Java app to App Service.
249+
**Congratulations!** You deployed your first Java app to App Service.
163250

164251
## 5 - Clean up resources
165252

@@ -169,4 +256,4 @@ In the preceding steps, you created Azure resources in a resource group. If you
169256
az group delete --name <your resource group name; for example: quarkus-hello-azure-1690375364238-rg> --yes
170257
```
171258
172-
This command may take a minute to run.
259+
This command might take a minute to run.
46.6 KB
Loading
14.5 KB
Loading

articles/app-service/quickstart-java.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ keywords: azure, app service, web app, windows, linux, java, maven, quickstart
55
ms.assetid: 582bb3c2-164b-42f5-b081-95bfcb7a502a
66
ms.devlang: java
77
ms.topic: quickstart
8-
ms.date: 08/31/2023
8+
ms.date: 02/10/2024
99
ms.custom: mvc, mode-other, devdivchpfy22, devx-track-java, devx-track-javaee-jbosseap-appsvc, devx-track-javaee-jbosseap, devx-track-javaee, devx-track-extended-java
1010
zone_pivot_groups: app-service-java-hosting
1111
adobe-target: true
@@ -25,9 +25,9 @@ ms.author: cephalin
2525

2626
::: zone-end
2727

28-
::: zone pivot="java-maven-quarkus"
28+
::: zone pivot="java-maven-javase"
2929

30-
[!INCLUDE [quickstart-java-windows-maven-pivot.md](./includes/quickstart-java/quickstart-java-quarkus.md)]
30+
[!INCLUDE [quickstart-java-windows-maven-pivot.md](./includes/quickstart-java/quickstart-java-javase.md)]
3131

3232
::: zone-end
3333

articles/zone-pivot-groups.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ groups:
12251225
title: App Service Java hosting
12261226
prompt: Choose how you want to deploy your Java app
12271227
pivots:
1228-
- id: java-maven-quarkus
1228+
- id: java-maven-javase
12291229
title: Embed your own server
12301230
- id: java-maven-tomcat
12311231
title: To a Tomcat server
@@ -3007,4 +3007,4 @@ groups:
30073007
- id: blob-storage-quickstart-scratch
30083008
title: Build from scratch
30093009
- id: blob-storage-quickstart-template
3010-
title: Start with a template
3010+
title: Start with a template

0 commit comments

Comments
 (0)