How can I programmatically create a new resource group, and doc intelligence and storage account resources in that newly created group in Java?

Michael Wei 0 Reputation points
2025-06-12T14:24:37.94+00:00

My goal is to programmatically create a new resource group, and create a doc intelligence and storage account in that newly created group in Java. I've looked at some of the ARM SDK for Java documentation but it seems outdated and is causing some errors.

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,093 questions
{count} votes

1 answer

Sort by: Newest
  1. Vinodh247 34,491 Reputation points MVP Volunteer Moderator
    2025-06-13T00:54:22.1166667+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    To programmatically create a new Resource Group, Azure AI Doc Intelligence resource, and Storage Account in Java, you need to use the Azure SDK for Java (management libraries).

    1. Dependencies (Maven) : Use the latest version of these packages:
    2. Authenticate

    Use DefaultAzureCredential for local dev (ensure you have az login or AZURE_CLIENT_ID, etc. set up).

    import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.resourcemanager.AzureResourceManager; import com.azure.resourcemanager.resources.fluentcore.profile.AzureProfile; import com.azure.core.management.profile.AzureEnvironment; AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); AzureResourceManager azure = AzureResourceManager .authenticate(new DefaultAzureCredentialBuilder().build(), profile) .withDefaultSubscription();

    1. Creating Resource Group

    String resourceGroupName = "myResourceGroup"; String region = "eastus"; azure.resourceGroups().define(resourceGroupName) .withRegion(region) .create();

    1. Create Storage Account

    import com.azure.resourcemanager.storage.models.SkuName; import com.azure.resourcemanager.storage.models.Kind; String storageAccountName = "myuniquestorage" + System.currentTimeMillis(); // must be globally unique azure.storageAccounts().define(storageAccountName) .withRegion(region) .withExistingResourceGroup(resourceGroupName) .withSku(SkuName.STANDARD_LRS) .withKind(Kind.STORAGE_V2) .create();

    1. Create Azure AI Document Intelligence

    The AI Document Intelligence API is part of Cognitive Services, so you create a Cognitive Services Account of kind "FormRecognizer".

    import com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager;
    import com.azure.resourcemanager.cognitiveservices.models.Kind;
    import com.azure.resourcemanager.cognitiveservices.models.Sku;
    CognitiveServicesManager cognitiveServicesManager = CognitiveServicesManager
            .authenticate(new DefaultAzureCredentialBuilder().build(), profile);
    String cognitiveAccountName = "myformrecognizer" + System.currentTimeMillis();
    cognitiveServicesManager.accounts().define(cognitiveAccountName)
        .withRegion(region)
        .withExistingResourceGroup(resourceGroupName)
        .withKind(Kind.FORM_RECOGNIZER)
        .withSku(new Sku().withName("S0"))
        .withTags(Map.of("env", "dev"))
        .create();
    
    
    

    Note:

    1. Ensure that the Form Recognizer (Doc Intelligence) resource kind is correct: Kind.FORM_RECOGNIZER.
    2. You need to register Microsoft.CognitiveServices and Microsoft.Storage resource providers in your subscription if not already registered.
    3. The names (especially for Storage and Cognitive accounts) must be globally unique.

    The azure-resourcemanager SDK is actively maintained, but make sure you use the correct combination of AzureResourceManager and CognitiveServicesManager, the two operate differently.

    HTH!

    Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.


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.