azure-docs-sdk-java/docs-ref-conceptual/java-sdk-azure-overview.md

3.5 KiB

title description keywords author ms.author manager ms.date ms.topic ms.prod ms.technology ms.devlang ms.service ms.assetid
Azure libraries for Java Overview of the Azure management and service libraries for Java Azure, Java, SDK, API rloutlaw routlaw douge 04/16/2017 article azure azure java multiple 9aaf22a2-382a-4b13-a8e3-0e467d607207

Azure libraries for Java

The Azure libraries for Java help you manage Azure resources and connect to services from your application code. The libraries are available as Maven imports for use in your Java projects.

Manage Azure resources

Create and manage Azure resources from your Java applications using the Azure management libraries for Java. Use these libraries to build your own Azure automation tools and services.

For example, to create a Linux VM you would write the following code:

VirtualMachine linuxVM = azure.virtualMachines().define("myAzureVM")
           .withRegion(region)
           .withExistingResourceGroup("sampleResourceGroup")
           .withNewPrimaryNetwork("10.0.0.0/28")
           .withPrimaryPrivateIpAddressDynamic()
           .withoutPrimaryPublicIpAddress()
           .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
           .withRootUsername(userName)
           .withSsh(key)
           .withUnmanagedStorage()
           .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
           .create();

Review the install instructions for a full list of the libraries and how to import them into your projects and then read the get started article to set up your authentication and run sample code against your own Azure subscription.

Connect to Azure services

In addition to using Java libraries to create and manage resources within Azure, you can also use Java libraries to connect and use those resources in your apps. For example, you might update a table SQL Database or store files in Azure Storage. Select the library you need for a particular service from the complete list of libraries and visit the Java developer center for tutorials and sample code for help using them in your apps.

For example, to print out the contents of every blob in an Azure storage container:

// get the container from the blob client
CloudBlobContainer container = blobClient.getContainerReference("blobcontainer");

// For each item in the container
for (ListBlobItem blobItem : container.listBlobs()) {
    // If the item is a blob, not a virtual directory
    if (blobItem instanceof CloudBlockBlob) {
        // Download the text
        CloudBlockBlob retrievedBlob = (CloudBlockBlob) blobItem;
        System.out.println(retrievedBlob.downloadText());
    }
}

Sample code and reference

The following samples cover common automation tasks with the Azure management libraries for Java and have code ready to use in your own apps:

A reference is available for all packages in both the service and management libraries. New features, breaking changes, and migration instructions from previous versions are available in the release notes.