[英]FileNotFoundException using JAR command to unzip WAR in Batch file
[英]How to unzip a WAR file in command line
首先,我知道可以在命令行中使用jar
解压缩WAR文件。
问题是在目标机器上没有安装JDK,只有JRE。 我们不能依赖Windows来解压缩文件,因为它不支持很长的路径。
如果只安装了JRE,如何在命令行中解压缩WAR文件?
WAR文件只是一个ZIP文件,您可以使用任何Zip工具(如7-Zip)解压缩它。 如果您没有访问管理员帐户,您只需下载任何zip存档的可移植版本 ,不需要管理员密码。
只是为了记录,我将分享我从这个答案得到的解决方案。
我在我的问题中指出,我也遇到了长路问题,我用New-PSDrive解决了这个问题,这个功能可以让你映射一个临时驱动器。 我只在工作文件夹上映射了一个临时驱动器,我将其解压缩。
function Unzip-File($file) {
$path = [io.path]::GetDirectoryName($file.FullName)
$filename = [io.path]::GetFileNameWithoutExtension($file.FullName)
$targetPath = Join-Path $path $filename;
# Check if the directory exists.
if(Test-Path $targetPath) {
# Remove the directory before unzipping.
Remove-Item $targetPath -recurse
}
# Unzip file.
Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($file, $targetPath)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.