I want to use sdk for java.

hmkwon@lgcns.com 21 Reputation points
2021-02-04T11:58:35.167+00:00

I want to get a list and details of virtual machines using Java.

I'd like to know about related samples and methods, but I got a 404 error in the Azure document

I would like to receive documentation or guides on how to use sdk and fetch VM information.

Thank you.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,015 questions
0 comments No comments
{count} votes

Accepted answer
  1. prmanhas-MSFT 17,946 Reputation points Microsoft Employee Moderator
    2021-02-05T11:15:02.76+00:00

    @hmkwon@lgcns.com Apologies for the delay in response and all the inconvenience caused because of the issue.

    You can refer to this article where it is mentioned how to get information about Virtual Machines using Java SDK:

    VirtualMachine virtualMachine = computeManager.virtualMachines()
    .getByResourceGroup(<your resource group>, <your virtual machine>);

    Also you can refer to below official documentation as well for Supported Java SDK for Virtual Machines:

    https://learn.microsoft.com/en-us/azure/virtual-machines/windows/java

    https://azure.github.io/azure-sdk-for-java/

    One such old sample is here too:

    The current version of azure java sdk supports listing virtual machines. You need to import following packages

    group: 'com.microsoft.azure', name: 'azure', version: '1.12.0'
    group: 'commons-net', name: 'commons-net', version: '3.3'
    group: 'com.microsoft.azure', name: 'azure-storage', version: '8.0.0'

    Then authenticate with client id and client secret

    ApplicationTokenCredentials credentials = new ApplicationTokenCredentials('<client id>', '<tenant id>', '<client secret>', AzureEnvironment.AZURE);
    Azure azure = Azure.authenticate(credentials).withSubscription('SubscriptionGuid');
    Then use the following code to list virtual machines

    PagedList<VirtualMachine> vms = azure.virtualMachines().list();

    Hope it helps!!!

    Please "Accept as Answer" if it helped so it can help others in community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.