Powershell远程安装Java怎么实现
来源:爱站网时间:2022-01-04编辑:网友分享
很多人都不清楚怎么在Powershell实现远程安装Java的操作,想要了解这方面内容的朋友,不如跟爱站技术频道小编来一起看看以下相关资料,有需要可以来看一看。
问题描述
我正在尝试在VSTS管道中使用PowerShell在azure VM上运行Apache jMeter。问题是azure VM是新创建的,默认情况下没有安装JDK。由于jMeter需要'java',所以它抛出以下错误。
C:\apache-jmeter-5.2.1\bin>jmeter -n -t C:\User-search.jmx -l C:\
Not able to find Java executable or version. Please check your Java installation.
errorlevel=2
我需要在运行jMeter之前安装Java。有什么方法可以使用Powershell远程安装Java吗?
或者如果预安装的java有可用的Windows Azure虚拟机映像?
思路一:
您可以使用Powershell Remoting在任何计算机上执行任意命令,最简单的安装Java Runtime的方法是使用Chocolatey package manager,它应该像这样简单:
choco install javaruntime -y
参考:
- Installing Java Runtime in Azure Cloud Services with Chocolatey
- How to Run External Commands and Programs Locally and Remotely from JMeter
思路二:
首先与虚拟机建立会话,然后运行以下脚本。
#Download and silent install JDK
#Working directory path
Write-Host "Creating temp working directory..."
$workd = "c:\temp"
#Check if work directory exists if not create it
If (!(Test-Path -Path $workd -PathType Container))
{
New-Item -Path $workd -ItemType directory
}
#Create config file for silent install
Write-Host "Creating config file for silent install..."
$text = '
INSTALL_SILENT=Enable
AUTO_UPDATE=Enable
SPONSORS=Disable
REMOVEOUTOFDATEJRES=1
'
$text | Set-Content "$workd\jdkinstall.cfg"
#Download executable file
Write-Host "Download JDK file to temp directory..."
$source = "https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.exe"
$destination = "$workd\jdk-13.0.2_windows-x64_bin.exe"
$client = New-Object System.Net.WebClient
$cookie = "oraclelicense=accept-securebackup-cookie"
$client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
$client.DownloadFile($source, $destination)
Write-Host "Download JDK file completed !"
#Install silently
Write-Host "Trying to install JDK silently..."
Start-Process -FilePath "$workd\jdk-13.0.2_windows-x64_bin.exe" -ArgumentList INSTALLCFG="$workd\jdkinstall.cfg" -Wait
Write-Host "JDK installation completed successfully !"
#Remove the installer
Write-Host "Trying to remove JDK file from temp directory..."
rm -Force $workd\jdk*
Write-Host "JDK file deleted successfully !"
Powershell远程安装Java怎么实现内容看完了吗,对此还不是特别明白的,不如多刷几次看看。想要了解更多精彩技术内容,来爱站技术频道网站即可。
下一篇:参数x的函数如何在JSTL中设置