首页 > 解决方案 > 如何使用 powershell 脚本下载最新的 java 版本 8

问题描述

我正在使用以下命令在其中一个 Windows 打包程序实例上安装 Java,但是,我遇到了以下错误;

Cannot index into a null array.
At line:1 char:94
+ ... content | %{[regex]::matches($_, '(?:<a title="Download Java software ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

命令:-

[Net.ServicePointManager]::SecurityProtocol = "tls12"

$URL = (Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows .64-bit." href=")(.*)(?:">)').Groups[1].Value}

Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL

Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait

看起来 Oracle 已从导致错误的网页中删除了标题字符串内容。是否有另一种方法/命令可以使用 powershell 安装它?

标签: javapowershellpacker

解决方案


推荐阅读