java - Azure Java SDK - 类去哪儿了

标签 java azure azure-management-api azure-java-sdk

我正在使用 Java sdk 尝试自动执行一些 Azure 任务,例如启动服务器和关闭服务器。 我使用的是 maven 的 java sdk 版本 0.9.0

           <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-svc-mgmt</artifactId>
                <version>0.9.0</version>
            </dependency>   

            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-svc-mgmt-compute</artifactId>
                <version>0.9.0</version>
            </dependency>

这段代码在eclipse中编译并成功运行

 package com.services.servers.operations.azure;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.compute.ComputeManagementClient;
import com.microsoft.windowsazure.management.compute.ComputeManagementService;
import com.microsoft.windowsazure.management.compute.VirtualMachineOperations;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;

public class AzureTest {

    String uri = "https://management.core.windows.net/";
    String subscriptionId = "dasdas9-86da-4343-a1f4-24c20864e166";
    String keyStoreLocation = "C:\\Users\\test\\Desktop\\azure\\testKeystore.jks";
    String keyStorePassword = "password";

    public boolean startVirtualMachine(String serviceName, String deploymentName, String virtualMachineName){

        boolean isSuccess = true;

        try {            

            VirtualMachineOperations virtualMachineOperations = null;

            Configuration config = ManagementConfiguration.configure(
                        new URI(uri), 
                          subscriptionId,
                          keyStoreLocation, 
                          keyStorePassword, 
                          KeyStoreType.jks 
                      );

            ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);

            virtualMachineOperations = computeManagementClient.getVirtualMachinesOperations();

            virtualMachineOperations.beginStarting(serviceName, deploymentName, virtualMachineName);

        } catch (IOException e) {
            System.out.println("An IOException has occured. Exception: " +e);
            isSuccess = false;
        }  catch (ServiceException e) {
            System.out.println("A ServiceException has occured. Exception: " + e);
            isSuccess = false;
        } catch (URISyntaxException e) {
            System.out.println("A URISyntaxException has occured. Exception: " + e);
            isSuccess = false;
        }         


        return isSuccess;
    }

}

当我升级到最新版本的 sdk - 0.9.1 - 以下类不再存在

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;

我在网上找不到任何内容来说明这些类的去向 - 它们是否已被弃用或更多到另一个库

如果有人知道我应该改用哪些类或者他们可能已经转移到哪些库——那就太好了 或者,如果有人可以对上述代码提出任何改进以启动服务器,我们将不胜感激

谢谢 达米安

最佳答案

我尝试重现该问题,但收到错误无法读取 com.microsoft.azure:azure-svc-mgmt...jar:0.9.0 的工件描述符

该问题似乎是由用于下载 Microsoft Azure SDK for Management 版本 0.9.1 依赖项的 Maven 存储库引起的。

我建议您目前可以使用0.9.0版本。

如果您必须使用版本 0.9.1,您可以在 pom.xml 文件中手动添加库及其依赖项的完整 Maven 列表,或者您可以手动下载所有库文件并将其添加到项目类路径中。

关于java - Azure Java SDK - 类去哪儿了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693920/

相关文章:

azure - 如何以编程方式查找到目前为止我已消耗了多少 Azure 存储空间?

c# - 如何在 Azure Fluent API for SQL Server 中为现有数据库设置服务器级别目标(定价层)?

java - 在多模块 Maven 项目中,我在哪里存储集成功能(文件)?

javascript - 从文件路径构建树

azure - 如何通过 Management Rest API 在 Azure Web Apps 上设置 SSL 绑定(bind)?

azure - 如何仅在一条触发消息上多次执行相同的 webjob 方法?

sql - 如何在 Azure SQL 中使用 terraform 添加 azurerm_mssql_database 的只读副本

java - 您可以中止 POI eventmodel 中的处理表吗

java - 修改过滤器链 - 或者选择servlet使用过滤器响应请求

azure - 如何更改 Azure AD 上的用户主体名称