Skip to content

Commit 55496da

Browse files
authored
Merge pull request #274638 from hangwan97/launchfirstjava
Launch your first java app
2 parents eacca7d + 1638a1a commit 55496da

File tree

8 files changed

+199
-112
lines changed

8 files changed

+199
-112
lines changed

articles/container-apps/.openpublishing.redirection.container-apps.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"redirect_url": "/azure/container-apps/dapr-overview",
66
"redirect_document_id": false
77
},
8+
{
9+
"source_path_from_root": "/articles/container-apps/java-deploy-war-file.md",
10+
"redirect_url": "/azure/container-apps/java-get-started",
11+
"redirect_document_id": false
12+
},
813
{
914
"source_path_from_root": "/articles/container-apps/secure-app.md",
1015
"redirect_url": "/azure/container-apps/manage-secrets",

articles/container-apps/TOC.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- name: Use serverless containers
1212
href: start-serverless-containers.md
1313
- name: Quickstarts
14-
items:
14+
items:
1515
- name: Deploy from an existing container image
1616
items:
1717
- name: Azure portal
@@ -49,7 +49,7 @@
4949
- name: Environment
5050
href: environment.md
5151
- name: Containers
52-
href: containers.md
52+
href: containers.md
5353
- name: Revisions
5454
href: revisions.md
5555
- name: Application lifecycle management
@@ -113,7 +113,7 @@
113113
- name: Revision management
114114
href: revisions-manage.md
115115
- name: Environment Variables
116-
href: environment-variables.md
116+
href: environment-variables.md
117117
- name: Use health probes
118118
href: health-probes.md
119119
- name: Storage mounts
@@ -136,7 +136,7 @@
136136
items:
137137
- name: Overview
138138
href: observability.md
139-
- name: Application logging
139+
- name: Application logging
140140
href: logging.md
141141
- name: Real time data
142142
href: aspire-dashboard.md
@@ -168,7 +168,7 @@
168168
href: custom-domains-managed-certificates.md
169169
displayName: Set up custom domain with a managed certificate
170170
- name: Set up custom domain with existing certificate
171-
href: custom-domains-certificates.md
171+
href: custom-domains-certificates.md
172172
- name: Set up environment custom DNS suffix
173173
href: environment-custom-dns-suffix.md
174174

@@ -215,7 +215,7 @@
215215
- name: Dedicated hardware
216216
items:
217217
- name: Workload profiles
218-
href: workload-profiles-overview.md
218+
href: workload-profiles-overview.md
219219
- name: Manage workload profiles
220220
items:
221221
- name: CLI
@@ -231,7 +231,7 @@
231231
- name: Get started
232232
items:
233233
- name: Connect to Azure services via Dapr components
234-
href: dapr-component-connection.md
234+
href: dapr-component-connection.md
235235
- name: Enable Dapr
236236
href: enable-dapr.md
237237
- name: Configure
@@ -242,7 +242,7 @@
242242
href: dapr-component-resiliency.md
243243
- name: Scale Dapr apps with KEDA using Bicep
244244
href: dapr-keda-scaling.md
245-
- name: Enable token authentication for Dapr requests
245+
- name: Enable token authentication for Dapr requests
246246
href: dapr-authentication-token.md
247247
- name: Tutorials
248248
items:
@@ -269,7 +269,7 @@
269269
- name: Deploy with an internal environment
270270
href: vnet-custom-internal.md
271271
- name: Ingress
272-
items:
272+
items:
273273
- name: Overview
274274
href: ingress-overview.md
275275
- name: Configure ingress
@@ -313,6 +313,9 @@
313313
- name: Overview
314314
href: java-overview.md
315315
displayName: java
316+
- name: Launch your first Java app
317+
href: java-get-started.md
318+
displayName: java
316319
- name: Automatic memory fitting
317320
href: java-memory-fit.md
318321
displayName: java
@@ -326,9 +329,6 @@
326329
displayName: java
327330
- name: Tutorials
328331
items:
329-
- name: Deploy a WAR file
330-
href: java-deploy-war-file.md
331-
displayName: java
332332
- name: Connect to Eureka Server for Spring
333333
href: java-eureka-server.md
334334
- name: Connect to Config Server for Spring

articles/container-apps/deploy-artifact.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Copy the FQDN to a web browser. From your web browser, go to the `/albums` endpo
181181

182182
## Deploy a WAR file
183183

184-
You can also deploy your container app from a [WAR file](java-deploy-war-file.md).
184+
You can also deploy your container app from a [WAR file](java-get-started.md?tabs=war).
185185

186186
## Clean up resources
187187

articles/container-apps/java-deploy-war-file.md

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
title: Launch your first Java application in Azure Container Apps
3+
description: Learn how to deploy a java project in Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.custom: devx-track-extended-java
8+
ms.topic: quickstart
9+
ms.date: 05/07/2024
10+
ms.author: cshoe
11+
zone_pivot_groups: container-apps-java-artifacts
12+
---
13+
14+
# Quickstart: Launch your first Java application in Azure Container Apps
15+
16+
This article shows you how to deploy the Spring PetClinic sample application to run on Azure Container Apps. Rather than manually creating a Dockerfile and directly using a container registry, you can deploy your Java application directly from a Java Archive (JAR) file or a web application archive (WAR) file.
17+
18+
By the end of this tutorial you deploy a web application, which you can manage through the Azure portal.
19+
20+
The following image is a screenshot of how your application looks once deployed to Azure.
21+
22+
:::image type="content" source="media/java-deploy-war-file/azure-container-apps-petclinic-warfile.png" alt-text="Screenshot of petclinic app.":::
23+
24+
## Prerequisites
25+
26+
| Requirement | Instructions |
27+
|--|--|
28+
| Azure account | If you don't have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).<br><br>You need the *Contributor* or *Owner* permission on the Azure subscription to proceed. <br><br>Refer to [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml?tabs=current) for details. |
29+
| GitHub Account | Get one for [free](https://github.com/join). |
30+
| git | [Install git](https://git-scm.com/downloads) |
31+
| Azure CLI | Install the [Azure CLI](/cli/azure/install-azure-cli).|
32+
| Java | Install the [Java Development Kit](/java/openjdk/install). Use version 17 or later. |
33+
| Maven | Install the [Maven](https://maven.apache.org/download.cgi).|
34+
35+
## Prepare the project
36+
37+
Clone the Spring PetClinic sample application to your machine.
38+
39+
::: zone pivot="jar"
40+
41+
```bash
42+
git clone https://github.com/spring-projects/spring-petclinic.git
43+
```
44+
45+
::: zone-end
46+
47+
::: zone pivot="war"
48+
49+
```bash
50+
git clone https://github.com/spring-petclinic/spring-framework-petclinic.git
51+
```
52+
53+
::: zone-end
54+
55+
## Build the project
56+
57+
::: zone pivot="jar"
58+
59+
60+
Change into the *spring-petclinic* folder.
61+
62+
```bash
63+
cd spring-petclinic
64+
```
65+
66+
Clean the Maven build area, compile the project's code, and create a JAR file, all while skipping any tests.
67+
68+
```bash
69+
mvn clean package -DskipTests
70+
```
71+
72+
After you execute the build command, a file named *petclinic.jar* is generated in the */target* folder.
73+
74+
::: zone-end
75+
76+
::: zone pivot="war"
77+
78+
> [!NOTE]
79+
> If necessary, you can specify the Tomcat version in the [Java build environment variables](java-build-environment-variables.md).
80+
81+
Change into the *spring-framework-petclinic* folder.
82+
83+
```bash
84+
cd spring-framework-petclinic
85+
```
86+
87+
Clean the Maven build area, compile the project's code, and create a WAR file, all while skipping any tests.
88+
89+
```bash
90+
mvn clean package -DskipTests
91+
```
92+
93+
After you execute the build command, a file named *petclinic.war* is generated in the */target* folder.
94+
95+
::: zone-end
96+
97+
## Deploy the project
98+
99+
::: zone pivot="jar"
100+
101+
Deploy the JAR package to Azure Container Apps.
102+
103+
> [!NOTE]
104+
> If necessary, you can specify the JDK version in the [Java build environment variables](java-build-environment-variables.md).
105+
106+
Now you can deploy your WAR file with the `az containerapp up` CLI command.
107+
108+
```azurecli
109+
az containerapp up \
110+
--name <CONTAINER_APP_NAME> \
111+
--resource-group <RESOURCE_GROUP> \
112+
--subscription <SUBSCRIPTION_ID>\
113+
--location <LOCATION> \
114+
--environment <ENVIRONMENT_NAME> \
115+
--artifact <JAR_FILE_PATH_AND_NAME> \
116+
--ingress external \
117+
--target-port 8080 \
118+
--query properties.configuration.ingress.fqdn
119+
```
120+
121+
> [!NOTE]
122+
> The default JDK version is 17. If you need to change the JDK version for compatibility with your application, you can use the `--build-env-vars BP_JVM_VERSION=<YOUR_JDK_VERSION>` argument to adjust the version number.
123+
124+
You can find more applicable build environment variables in [Java build environment variables](java-build-environment-variables.md).
125+
126+
::: zone-end
127+
128+
::: zone pivot="war"
129+
130+
Deploy the WAR package to Azure Container Apps.
131+
132+
Now you can deploy your WAR file with the `az containerapp up` CLI command.
133+
134+
```azurecli
135+
az containerapp up \
136+
--name <CONTAINER_APP_NAME> \
137+
--resource-group <RESOURCE_GROUP> \
138+
--subscription <SUBSCRIPTION>\
139+
--location <LOCATION> \
140+
--environment <ENVIRONMENT_NAME> \
141+
--artifact <WAR_FILE_PATH_AND_NAME> \
142+
--build-env-vars BP_TOMCAT_VERSION=10.* \
143+
--ingress external \
144+
--target-port 8080 \
145+
--query properties.configuration.ingress.fqdn
146+
```
147+
148+
> [!NOTE]
149+
> The default Tomcat version is 9. If you need to change the Tomcat version for compatibility with your application, you can use the `--build-env-vars BP_TOMCAT_VERSION=<YOUR_TOMCAT_VERSION>` argument to adjust the version number.
150+
151+
In this example, the Tomcat version is set to `10` (including any minor versions) by setting the `BP_TOMCAT_VERSION=10.*` environment variable.
152+
153+
You can find more applicable build environment variables in [Java build environment variables](java-build-environment-variables.md).
154+
155+
::: zone-end
156+
157+
## Verify app status
158+
159+
In this example, `containerapp up` command includes the `--query properties.configuration.ingress.fqdn` argument, which returns the fully qualified domain name (FQDN), also known as the app's URL.
160+
161+
View the application by pasting this URL into a browser. Your app should resemble the following screenshot.
162+
163+
:::image type="content" source="media/java-deploy-war-file/azure-container-apps-petclinic-warfile.png" alt-text="Screenshot of petclinic application.":::
164+
165+
## Next steps
166+
167+
> [!div class="nextstepaction"]
168+
> [Java build environment variables](java-build-environment-variables.md)

0 commit comments

Comments
 (0)