The script from Jeremy Davis Downloads, installs, adds SSL and sets up Solr as windows service. However, JRE is required for Solr and JRE needs to be installed manually. Is there anyway to download and install JRE with PowerShell?
2 Answers
Actually, I did find out a way to download and install JRE with PowerShell script.It is really use-full therefore I wanted to share it here in StackExchange. This script can be optimized but it does the job as it is.
Below is the entire script: https://github.com/erjan123/Sitecore/blob/master/Sitecore/PowershellScripts/Sitecore%20Solr/2.install-solr-7.5-and-JRE.ps1
I have also a tutorial that explains the script: https://www.youtube.com/watch?v=3-27syl8C98&t=10s
Param(
$downloadInstallJRE = $true,
$JREVersion64 = $true
)
if($downloadInstallJRE -eq $true)
{
if($JREVersion64 -eq $true)
{
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | ForEach-Object{[regex]::matches($_, '(?:<a title="Download Java software for Windows \(64-bit\)" href=")(.*)(?:">)').Groups[1].Value}
}
else
{
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | ForEach-Object{[regex]::matches($_, '(?:<a title="Download Java software for Windows Online" href=")(.*)(?:">)').Groups[1].Value}
}
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
if($JREVersion64 -eq $true)
{
$JREVersion = Get-ChildItem -Path "C:\Program Files\Java" -name | Where-Object { -not $_.PsIsContainer } | Sort-Object LastWriteTime -Descending | Select-Object -first 1
Write-Host "JREVersion: $JREVersion"
$JREPath = "C:\Program Files\Java\$JREVersion"
Write-Host "JREPath" + $JREPath
Write-Host "Downloading 64 bit of JRE"
}
else{
$JREVersion = Get-ChildItem -Path "C:\Program Files (x86)\Java" -name | Where-Object { -not $_.PsIsContainer } | Sort-Object LastWriteTime -Descending | Select-Object -first 1
Write-Host "JREVersion: $JREVersion"
$JREPath = "C:\Program Files (x86)\Java\$JREVersion"
Write-Host "JREPath " + $JREPath
Write-Host "Downloading 32 bit of JRE"
}
Write-Host "JRE package URL " $URL
}
Annoyingly you can no longer scrape the page as in the accepted answer and need to grab the URL manually first.
$URL="https://javadl.oracle.com/webapps/download/AutoDL?BundleId=244422_26081f2c2d854520a890cbbc4a1d8fee"
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
$JREVersion = Get-ChildItem -Path "C:\Program Files\Java" -name | Where-Object { -not $_.PsIsContainer } | Sort-Object LastWriteTime -Descending | Select-Object -first 1
Write-Host "JREVersion: $JREVersion"
$JREPath = "C:\Progra~1\Java\$JREVersion"
Write-Host "JREPath" + $JREPath
Write-Host "Downloading 64 bit of JRE"
Write-Host "JRE package URL " $URL
-
I get a response of "Unrecognized arguments". BundleId is no longer valid. The java 8.321 bundleId=245791_df5ad55fdd604472a86a45a217032c7d and java 8.431 bundleid = 246808_424b9da4b48848379167015dcc250d8d if that helps anyone doing something similar.– JimCommented Sep 21, 2022 at 13:07