我正在使用 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/