Java command still not found after configuring JDK environment variable correctly

后端 未结 1 994
执念已碎
执念已碎 2021-01-28 05:40

I do a thing to install JDK when a Windows virtual machine boot, use a cloudinit user-data to transfer a PowerShell script to the windows machine, and run the script to install

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 06:19

    Environment variables are stored in the registry. [Environment]::SetEnvironmentVariable() writes the given variable as a REG_SZ value, but for nested variables to be expanded you need a REG_EXPAND_SZ value.

    If you want to use %JAVA_HOME%\bin in the PATH use Set-ItemProperty instead of [Environment]::SetEnvironmentVariable():

    $regkey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
    Set-ItemProperty -Path $regkey -Name 'Path' -Value $path -Type ExpandString
    

    Beware that there may be other pitfalls when using nested variables in environment variables due to the order in which they're expanded. Raymond Chen described the behavior in the article Windows Confidential: The hidden variables.

    0 讨论(0)
提交回复
热议问题