当我运行此代码时:
Configuration azureConfig = ManagementConfiguration.configure(
new URI("https://management.core.windows.net/"),
"asdasdasd",
"server.keystore",
"asdasdasd",
KeyStoreType.jks
);
ManagementClient client = ManagementService.create(azureConfig);
LocationsListResponse response = client.getLocationsOperations().list();
ArrayList locations = response.getLocations();
for( int i=0; i<locations.size(); i++){
System.out.println(((LocationsListResponse.Location)locations.get(i)).getDisplayName());
}
我明白了:
00:52:04 [SEVERE] java.lang.RuntimeException: Service or property not registered: com.microsoft.windowsazure.management.ManagementClient interface com.microsoft.windowsazure.management.ManagementClient
00:52:04 [SEVERE] at com.microsoft.windowsazure.core.DefaultBuilder.build(DefaultBuilder.java:197)
00:52:04 [SEVERE] at com.microsoft.windowsazure.Configuration.create(Configuration.java:113)
00:52:04 [SEVERE] at com.microsoft.windowsazure.management.ManagementService.create(ManagementService.java:46)
00:52:04 [SEVERE] at {LINE OF CODE THAT CONTAINS ManagementClient client = ManagementService.create(azureConfig);}
在互联网上只有1个关于此的问题,关于Android并且没有明确的答复......有人解决了这个问题吗?
我在Azure with Java 1.8的虚拟机中使用OpenLogic 6.5(基于CentOS)运行它。
编辑:我创建了一个新项目并从eclipse启动它。我得到了正确的结果,但是当我从命令行(java -jar test.jar)启动它时,我收到完全相同的错误。
答案 0 :(得分:1)
我也遇到过类似的问题。明确设置上下文类加载器解决了问题
// Get current context class loader
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
// Change context classloader to class context loader
Thread.currentThread().setContextClassLoader(AzureManagementServiceDelegate.class.getClassLoader));
try {
// Call Azure API and reset back the context loader
} catch (Exception e) {
// handle exceptions
} finally {
// Reset back class loader
Thread.currentThread().setContextClassLoader(contextLoader);
}