Java tool installer task is failing with path in the azure devops

tarun k 280 Reputation points
2025-06-26T10:10:46.2933333+00:00

java tool installer task failing with following error

##[debug]win: true

Extracting archive to: C:\azp\agent_work_temp\JAVA_HOME_17_X64_OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8_zip

Creating destination folder: C:\azp\agent_work_temp\JAVA_HOME_17_X64_OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8_zip

##[debug]testing directory 'C:\azp\agent_work_temp\JAVA_HOME_17_X64_OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8_zip'

##[debug]testing directory 'C:\azp\agent_work_temp'

##[debug]mkdir 'C:\azp\agent_work_temp\JAVA_HOME_17_X64_OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8_zip'

##[error]ENOENT: no such file or directory, stat 'D:\Java\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip'

Please suggest

Azure DevOps
0 comments No comments
{count} votes

Accepted answer
  1. Durga Reshma Malthi 4,430 Reputation points Microsoft External Staff Moderator
    2025-06-26T10:53:40.3033333+00:00

    Hi tarun k

    You're running into an issue because the JavaToolInstaller task in your pipeline is trying to locate the JDK zip file at a Windows-specific path (D:\Java\...), but the agent running the job is a Windows Docker container, which does not have access to that drive or path.

    Could you please try the below steps:

    1. From your YAML code, Replace this: jdkFile: 'D:\Java\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip' on 54th line with jdkFile: '$(Build.SourcesDirectory)\tools\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip'
    2. Insert the below PowerShell script before the JavaToolInstaller task:
         - powershell: |
             Invoke-WebRequest -Uri "https://example.com/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip" `
                 -OutFile "$(Build.SourcesDirectory)\tools\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip"
           displayName: "Download Java 17 JDK Zip"
           condition: and(eq(variables['OSType'], 'Windows'), eq(parameters.java_version, '17'))
      
    3. Use a cloud-hosted JDK binary instead of relying on local disk, update the Windows section of your YAML like this:
         - task: JavaToolInstaller@0
           displayName: 'Install JDK in container agent'
           inputs:
             versionSpec: '17'
             jdkArchitectureOption: 'x64'
             jdkSourceOption: 'AzureStorage'
             azureResourceManagerEndpoint: '<YourServiceConnection>'
             azureStorageAccountName: '<StorageAccount>'
             azureContainerName: '<BlobContainer>'
             azureCommonVirtualPath: 'OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip'
             jdkDestinationDirectory: '$(Agent.ToolsDirectory)/jdk-17'
             cleanDestinationDirectory: false
      

    Alternatively, If you're using a Windows container that already has Java installed, you do not need to install the JDK manually.

    Instead of JavaToolInstaller@0, simply set the environment variable JAVA_HOME or PATH using the already installed JDK in the container.

    1. Remove or skip JavaToolInstaller@0
    2. Add the below script to check Java version:
         - powershell: |
             java -version
             echo "JAVA_HOME is set to: $env:JAVA_HOME"
           displayName: "Check existing Java in container"
           condition: eq(variables['OSType'], 'Windows')
      

    Additional References:

    https://stackoverflow.com/questions/61124946/how-to-you-use-a-specific-version-of-java-in-azure-devops-agent-without-download

    Hope this helps!

    Please Let me know if you have any queries.

    0 comments No comments

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.