azure java sdk_開始使用 Azure SDK for Java | Microsoft Docs

本文将引导您设置Java中的Azure开发环境,创建Azure资源并进行基本操作,如上传文件或部署Web应用。完成后,您将能够开始在自己的Java应用中使用Azure服务。先决条件包括Azure帐户、Java 8和Maven 3。文章还介绍了如何设置服务主体进行身份验证,并提供了使用Maven创建新项目的步骤。此外,还提供了在IntelliJ和Eclipse中安装Azure工具包的指南,以及创建Linux虚拟机、部署Web应用和连接到Azure SQL数据库的示例代码。
摘要由CSDN通过智能技术生成

開始使用 Azure 上的 Java 進行雲端開發Get started with cloud development using Java on Azure

11/20/2020

在此文章

本文會逐步引導您設定開發環境,以便在 Java 中進行 Azure 開發。This article walks you through setting up a development environment for Azure development in Java. 然後,您將建立一些 Azure 資源並連接到這些資源,以進行一些基本工作,例如上傳檔案或部署 web 應用程式。You'll then create some Azure resources and connect to them to do some basic tasks, like uploading a file or deploying a web application. 當您完成時,您就已做好準備可以開始在自有的 Java 應用程式中使用 Azure 服務。When you're finished, you'll be ready to start using Azure services in your own Java applications.

PrerequisitesPrerequisites

一個 Azure 帳戶。An Azure account. 如果您沒有帳戶,請取得免費試用帳戶。If you don't have one, get a free trial.

Java 8 (包含在 Azure Cloud Shell 中)。Java 8, which is included in Azure Cloud Shell.

Maven 3 (包含在 Azure Cloud Shell 內)。Maven 3, which is included in Azure Cloud Shell.

設定驗證Set up authentication

Java 應用程式必須有 Azure 訂用帳戶的讀取和建立權限,才能在此教學課程中執行程式碼範例。Your Java application needs read and create permissions in your Azure subscription to run the sample code in this tutorial. 請建立服務主體,並將應用程式設定為使用其認證來執行。Create a service principal, and configure your application to run with its credentials. 服務主體可讓您建立與身分識別相關聯的非互動式帳戶,而且對於此身分識別,您只賦予它應用程式執行時所需的權限。Service principals provide a way to create a noninteractive account associated with your identity to which you grant only the privileges your app needs to run.

az ad sp create-for-rbac --name AzureJavaTest

這會提供您下列格式的回覆:Which gives you a reply in the following format:

{

"appId": "a487e0c1-82af-47d9-9a0b-af184eb87646d",

"displayName": "AzureJavaTest",

"name": "http://AzureJavaTest",

"password": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",

"tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"

}

接下來,設定環境變數:Next, configure the environment variables:

AZURE_SUBSCRIPTION_ID:使用在 Azure CLI 2.0 中透過 az account show 所得到的 id 值。AZURE_SUBSCRIPTION_ID: Use the id value from az account show in the Azure CLI 2.0.

AZURE_CLIENT_ID:使用從服務主體輸出所擷取的 appId 值。AZURE_CLIENT_ID: Use the appId value from the output taken from a service principal output.

AZURE_CLIENT_SECRET:使用從服務主體輸出所得到的 password 值。AZURE_CLIENT_SECRET: Use the password value from the service principal output.

AZURE_TENANT_ID:使用從服務主體輸出所得到的 tenant 值。AZURE_TENANT_ID: Use the tenant value from the service principal output.

ToolingTooling

建立新的 Maven 專案Create a new Maven project

注意

本文使用 Maven 建置工具來建置和執行範例程式碼。This article uses the Maven build tool to build and run the sample code. 其他 build tools (例如 Gradle)也可以使用 Azure SDK for JAVA。Other build tools, such as Gradle, also work with the Azure SDK for Java.

透過命令列在系統上的新目錄中建立 Maven 專案。Create a Maven project from the command line in a new directory on your system.

mkdir java-azure-test

cd java-azure-test

mvn archetype:generate -DgroupId=com.fabrikam -DartifactId=AzureApp \

-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

此步驟會在 testAzureApp 目錄下建立基本的 Maven 專案。This step creates a basic Maven project under the testAzureApp directory. 在專案的 pom.xml 檔案中新增下列專案,以匯入本教學課程的範例程式碼中所使用的程式庫。Add the following entries into the project's pom.xml file to import the libraries used in the sample code in this tutorial.

com.azure

azure-identity

1.2.0

com.azure.resourcemanager

azure-resourcemanager

2.1.0

com.azure

azure-storage-blob

12.8.0

com.microsoft.sqlserver

mssql-jdbc

6.2.1.jre8

在最上層 project 元素底下新增 build

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值