简体   繁体   English

如何在命令行中解压缩WAR文件

[英]How to unzip a WAR file in command line

First, I know it's possible to unzip a WAR file using jar in command line. 首先,我知道可以在命令行中使用jar解压缩WAR文件。

The problem is that on the target machine, there is no JDK installed, only the JRE. 问题是在目标机器上没有安装JDK,只有JRE。 And we can't rely on Windows to unzip the file because it does not support well long path. 我们不能依赖Windows来解压缩文件,因为它不支持很长的路径。

How it's possible to unzip a WAR file in command line when you only have the JRE installed? 如果只安装了JRE,如何在命令行中解压缩WAR文件?

WAR file is just a ZIP file, you can unzip it using any Zip tool (like 7-Zip). WAR文件只是一个ZIP文件,您可以使用任何Zip工具(如7-Zip)解压缩它。 If you don't have an access admin account, you can just download portable version of any zip archive, which doesn't require admin password. 如果您没有访问管理员帐户,您只需下载任何zip存档的可移植版本 ,不需要管理员密码。

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. 我在我的问题中指出,我也遇到了长路问题,我用New-PSDrive解决了这个问题,这个功能可以让你映射一个临时驱动器。 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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM