PowerShell,自动化 Java JRE 11(Adoptium、Eclipse Temurin)安装和配置

问题描述 投票:0回答:1

我想自动安装 Adoptium。到目前为止,我已经能够下载最新版本的

.msi

$baseURL = "https://api.adoptium.net/v3/assets/feature_releases/11/ga"   # Adoptium binaries and links

# Get versions and then [0] of the array that is returned to get the latest version
$response = Invoke-RestMethod -Uri $baseURL
$latestVersion = ($response.version_data.openjdk_version)[0]

# Locate the Windows MSI Installer
$downloadURL = ""
foreach ($asset in $response.binaries) {
    if ($asset.architecture -eq "x64" -and $asset.image_type -eq "jre" -and $asset.os -eq "windows") {
        $downloadURL = $asset.installer.link
        $downloadPath = "$env:TEMP\$($asset.installer.name)"   # Contains just the msi file name
        break
    }
}

# Download and run the installer
$global:progressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadURL -OutFile $downloadPath
& $downloadPath

在此之后,我想自动化安装,但一直无法让它工作。到目前为止我已经做到了这一点,但它不起作用。我的目标是自动选择 JRE 安装程序中的四个可用选项:

  • 添加到 PATH(默认选择)
  • 关联.jar(默认选择)
  • 设置JAVA_HOME变量(默认不选择)
  • JavaSoft (Oracle) 注册表项(默认情况下未选择)

如何使用 Adoptium JRE 11 安装程序通过所有这四个选项来自动安装它?

# Define the path to the MSI installer
$installerPath = "$env:TEMP\OpenJDK11U-jre_x64_windows_hotspot_11.0.23_9.msi"

# Define the arguments for msiexec
$msiArgs = @(
    "/i", "$installerPath",    # Specify the path to the MSI installer
    "/qn",                      # Quiet mode (no UI)
    "/norestart",               # Do not restart after installation
    "INSTALLDIR=`"C:\Program Files\Java\jdk-11`"",  # Specify the installation directory (change as needed)
    "ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJNLPFileRunWith,FeatureJavaHome", # Specify features to install
    "SETUP_AUTO_UPDATE=0",      # Disable automatic updates
    "INSTALL_SILENT=Enable",    # Enable silent installation
    "ASSOCIATE_JNLP=Enable",    # Associate .jnlp files
    "ASSOCIATE_JAR=Enable",     # Associate .jar files
    "ASSOCIATE_JAD=Enable",     # Associate .jad files
    "INSTALLDIR_CONFESS=Enable" # Set installation directory
)

# Run msiexec with the defined arguments
Start-Process "msiexec.exe" -ArgumentList $msiArgs -Wait
java powershell windows-installer
1个回答
0
投票

如果您想安装所有功能,请更改 ADDLOCAL 属性的值:

ADDLOCAL=ALL

© www.soinside.com 2019 - 2024. All rights reserved.