【问题标题】:Azure Java SDK - Where have classes goneAzure Java SDK - 类去了哪里
【发布时间】:2016-01-09 13:17:34
【问题描述】:

我正在使用 Java sdk 来尝试自动化一些天蓝色的任务,例如启动服务器和关闭服务器。 我使用的是来自 maven 的 0.9.0 版的 java sdk

           <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;

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

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

谢谢 达米安

【问题讨论】:

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


    【解决方案1】:

    我尝试重现该问题,但收到错误 Failed to read artifact descriptor for 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 列表,或者您可以手动下载所有库文件并将其添加到项目类路径中。

    【讨论】:

    【解决方案2】:

    转到http://go.microsoft.com/fwlink/?linkid=690320&clcid=0x409,下载文件“PackageForAzureLibrariesForJava.zip”并将这些 jar 文件放入您的项目构建路径或在 pom 文件中添加依赖项(如果您使用的是 maven)。我已经在我的本地测试过这个。它有效。

    【讨论】: