First, I know it's possible to unzip a WAR file using jar
in command line.
The problem is that on the target machine, there is no JDK installed, only the JRE. And we can't rely on Windows to unzip the file because it does not support well long path.
How it's possible to unzip a WAR file in command line when you only have the JRE installed?
Just for the record I will share my solution that I've got from this answer.
I point in my question that I had also a problem with long path, a problem that I've solved with New-PSDrive, a function that let you map a temporary drive. I've only mapped a temporary drive on the working folder where I unzip stuff.
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)
}