java windows 应用_快速入门:在 Azure 应用服务中创建 Java 应用

快速入门:在 Azure 应用服务中创建 Java 应用Quickstart: Create a Java app on Azure App Service

02/01/2021

本文内容

Azure 应用服务提供高度可缩放、自修复的 Web 托管服务。Azure App Service provides a highly scalable, self-patching web hosting service. 本快速入门介绍如何将 Azure CLI 与用于 Maven 的 Azure Web 应用插件配合使用来部署 .jar 文件或 .war 文件。This quickstart shows how to use the Azure CLI with the Azure Web App Plugin for Maven to deploy a .jar file, or .war file. 使用选项卡在 Java SE 和 Tomcat 说明之间切换。Use the tabs to switch between Java SE and Tomcat instructions.

备注

也可使用 IntelliJ 和 Eclipse 等常见 IDE 执行相同的操作。The same can also be done using popular IDEs like IntelliJ and Eclipse.

5e3b5eeeb82800faaad4b9126a7ff420.png

如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅。If you don't have an Azure trail subscription, create a trial subscription before you begin.

备注

请先运行 az cloud set -n AzureChinaCloud 更改云环境,然后才能在 Azure 中国中使用 Azure CLI。Before you can use Azure CLI in Azure China , please run az cloud set -n AzureChinaCloud first to change the cloud environment. 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloud。If you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud again.

创建 Java 应用Create a Java app

git clone https://github.com/spring-guides/gs-spring-boot

将目录更改为已完成项目。Change directory to the completed project.

cd gs-spring-boot/complete

在本地 Shell 提示符下,执行以下 Maven 命令来创建一个名为 helloworld 的新应用:Execute the following Maven command in the local Shell prompt to create a new app named helloworld:

mvn archetype:generate "-DgroupId=example.demo" "-DartifactId=helloworld" "-DarchetypeArtifactId=maven-archetype-webapp" "-Dversion=1.0-SNAPSHOT"

然后,将工作目录更改为项目文件夹:Then change your working directory to the project folder:

cd helloworld

配置 Maven 插件Configure the Maven plugin

部署到 Azure 应用服务的过程会自动使用 Azure CLI 中的 Azure 凭据。The deployment process to Azure App Service will use your Azure credentials from the Azure CLI automatically. 如果未在本地安装 Azure CLI,则 Maven 插件将使用 Oauth 或设备登录名进行身份验证。If the Azure CLI is not installed locally, then the Maven plugin will authenticate with Oauth or device login.

运行下面的 Maven 命令来配置部署。Run the Maven command below to configure the deployment. 此命令将帮助你设置应用服务操作系统、Java 版本和 Tomcat 版本。This command will help you to set up the App Service operating system, Java version, and Tomcat version.

mvn com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config

当系统提示“订阅”选项时,通过在行首输入数字来选择适当的 Subscription。When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

当系统提示“Web 应用”选项时,按 Enter 键接受默认选项 或选择一个现有应用。When prompted with Web App option, accept the defaut option by pressing enter or select an existing app.

当系统提示 OS 选项时,通过输入 3 选择 Windows 。When prompted with OS option, select Windows by entering 3.

当系统提示“定价层”选项时,通过输入 2 选择 B2 。When prompted with Pricing Tier option, select B2 by entering 2.

按 Enter 使用默认的 Java 版本 Java 8。Use the default Java version, Java 8, by pressing enter.

最后,出现最后一个提示时按 Enter 来确认所做的选择。Finally, press enter on the last prompt to confirm your selections.

摘要输出将类似于下面所示的代码片段。Your summary output will look similar to the snippet shown below.

Please confirm webapp properties

Subscription Id : ********-****-****-****-************

AppName : spring-boot-1599007390755

ResourceGroup : spring-boot-1599007390755-rg

Region : chinanorth2

PricingTier : Basic_B2

OS : Windows

Java : 1.8

WebContainer : java 8

Deploy to slot : false

Confirm (Y/N)? : Y

[INFO] Saving configuration to pom.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 41.118 s

[INFO] Finished at: 2020-09-01T17:43:45-07:00

[INFO] ------------------------------------------------------------------------

当系统提示“订阅”选项时,通过在行首输入数字来选择适当的 Subscription。When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

当系统提示“Web 应用”选项时,按 Enter 键接受默认选项 或选择一个现有应用。When prompted with Web App option, accept the defaut option by pressing enter or select an existing app.

当系统提示 OS 选项时,通过输入 3 选择 Windows 。When prompted with OS option, select Windows by entering 3.

当系统提示“定价层”选项时,通过输入 2 选择 B2 。When prompted with Pricing Tier option, select B2 by entering 2.

按 Enter 使用默认的 Java 版本 Java 8。Use the default Java version, Java 8, by pressing enter.

按 Enter 使用默认 Web 容器 Tomcat 8.5。Use the default web container, Tomcat 8.5, by pressing enter.

最后,出现最后一个提示时按 Enter 来确认所做的选择。Finally, press enter on the last prompt to confirm your selections.

摘要输出将类似于下面所示的代码片段。Your summary output will look similar to the snippet shown below.

Please confirm webapp properties

Subscription Id : ********-****-****-****-************

AppName : helloworld-1599003152123

ResourceGroup : helloworld-1599003152123-rg

Region : chinanorth2

PricingTier : Basic_B2

OS : Windows

Java : 1.8

WebContainer : tomcat 8.5

Deploy to slot : false

Confirm (Y/N)? : Y

[INFO] Saving configuration to pom.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 03:03 min

[INFO] Finished at: 2020-09-01T16:35:30-07:00

[INFO] ------------------------------------------------------------------------

当系统提示“订阅”选项时,通过在行首输入数字来选择适当的 Subscription。When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

当系统提示“Web 应用”选项时,按 Enter 键接受默认选项 或选择一个现有应用。When prompted with Web App option, accept the defaut option by pressing enter or select an existing app.

当系统提示 OS 选项时,按 Enter 键选择 Linux 。When prompted with OS option, select Linux by pressing enter.

当系统提示“定价层”选项时,通过输入 2 选择 B2 。When prompted with Pricing Tier option, select B2 by entering 2.

按 Enter 使用默认的 Java 版本 Java 8。Use the default Java version, Java 8, by pressing enter.

最后,出现最后一个提示时按 Enter 来确认所做的选择。Finally, press enter on the last prompt to confirm your selections.

Please confirm webapp properties

Subscription Id : ********-****-****-****-************

AppName : spring-boot-1599007116351

ResourceGroup : spring-boot-1599007116351-rg

Region : chinanorth2

PricingTier : Basic_B2

OS : Linux

RuntimeStack : JAVA 8-jre8

Deploy to slot : false

Confirm (Y/N)? : Y

[INFO] Saving configuration to pom.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 20.925 s

[INFO] Finished at: 2020-09-01T17:38:51-07:00

[INFO] ------------------------------------------------------------------------

当系统提示“订阅”选项时,通过在行首输入数字来选择适当的 Subscription。When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

当系统提示“Web 应用”选项时,按 Enter 键接受默认选项 或选择一个现有应用。When prompted with Web App option, accept the defaut option by pressing enter or select an existing app.

当系统提示 OS 选项时,按 Enter 键选择 Linux 。When prompted with OS option, select Linux by pressing enter.

当系统提示“定价层”选项时,通过输入 2 选择 B2 。When prompted with Pricing Tier option, select B2 by entering 2.

按 Enter 使用默认的 Java 版本 Java 8。Use the default Java version, Java 8, by pressing enter.

按 Enter 使用默认 Web 容器 Tomcat 8.5。Use the default web container, Tomcat 8.5, by pressing enter.

最后,出现最后一个提示时按 Enter 来确认所做的选择。Finally, press enter on the last prompt to confirm your selections.

Please confirm webapp properties

Subscription Id : ********-****-****-****-************

AppName : helloworld-1599003744223

ResourceGroup : helloworld-1599003744223-rg

Region : chinanorth2

PricingTier : Basic_B2

OS : Linux

RuntimeStack : TOMCAT 8.5-jre8

Deploy to slot : false

Confirm (Y/N)? : Y

[INFO] Saving configuration to pom.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 50.785 s

[INFO] Finished at: 2020-09-01T16:43:09-07:00

[INFO] ------------------------------------------------------------------------

如果需要,可以直接在 pom.xml 中修改应用服务的配置。You can modify the configurations for App Service directly in your pom.xml if needed. 下面列出了一些常见配置:Some common ones are listed below:

属性Property

必须Required

说明Description

版本Version

falsefalse

指定配置架构的版本。Specify the version of the configuration schema. 支持的值是:v1、v2。Supported values are: v1, v2.

1.5.21.5.2

falsefalse

指定订阅 ID。Specify the subscription id.

0.1.0+0.1.0+

是true

用于 Web 应用的 Azure 资源组。Azure Resource Group for your Web App.

0.1.0+0.1.0+

是true

Web 应用的名称。The name of your Web App.

0.1.0+0.1.0+

是true

指定要托管 Web 应用的区域;默认值为“chinanorth2”。Specifies the region where your Web App will be hosted; the default value is chinanorth2. 支持的区域部分中列出了所有有效区域。All valid regions at Supported Regions section.

0.1.0+0.1.0+

falsefalse

Web 应用的定价层。The pricing tier for your Web App. 生产工作负载的默认值为 P1V2,而 B2 是建议用于 Java 开发/测试的最低值 。The default value is P1V2 for production workload, while B2 is the recommended minimum for Java dev/test. 了解详细信息Learn more

0.1.0+0.1.0+

是true

运行时环境配置,可以在此处查看详细信息。The runtime environment configuration, you could see the detail here.

0.1.0+0.1.0+

是true

部署配置,可以在此处查看详细信息。The deployment configuration, you could see the details here.

0.1.0+0.1.0+

请注意 和 的值(在演示中相应地为 helloworld-1590394316693 和 helloworld-1590394316693-rg),后面会使用它们。Be careful about the values of and (helloworld-1590394316693 and helloworld-1590394316693-rg accordingly in the demo), they will be used later.

部署应用Deploy the app

Maven 插件会使用 Azure CLI 中的帐户凭据来部署到应用服务。The Maven plugin uses account credentials from the Azure CLI to deploy to App Services.

az cloud set -n AzureChinaCloud

az login

然后你可使用以下命令将 Java 应用部署到 Azure。Then you can deploy your Java app to Azure using the following command.

mvn package azure-webapp:deploy

部署完成后,应用程序会在 http://.chinacloudsites.cn/(在演示中为 http://helloworld-1590394316693.chinacloudsites.cn)处准备就绪。Once deployment has completed, your application will be ready at http://.chinacloudsites.cn/(http://helloworld-1590394316693.chinacloudsites.cn in the demo). 在本地 Web 浏览器中打开 url,你应该会看到Open the url with your local web browser, you should see

5e3b5eeeb82800faaad4b9126a7ff420.png

祝贺你!Congratulations! 现已将第一个 Java 应用部署到应用服务。You've deployed your first Java app to App Service.

清理资源Clean up resources

在前面的步骤中,你在资源组中创建了 Azure 资源。In the preceding steps, you created Azure resources in a resource group. 如果认为将来不需要这些资源,请通过门户删除资源组,或在 Azure CLI 中运行以下命令:If you don't expect to need these resources in the future, delete the resource group from portal, or by running the following command in the Azure CLI:

az group delete --name --yes

此命令可能需要花费一点时间运行。This command may take a minute to run.

后续步骤Next steps

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值