Linux Command for Extracting War File

How to extract only one file from war file?

The -j flag is exactly what you need:

unzip -j test.war "*test.properties*" 

From the docs:

-j

junk paths. The archive's directory structure is not recreated; all
files are deposited in the extraction directory (by default, the
current one).

How to unzip a WAR file in command line

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)
}

How to extract .war files in java? ZIP vs JAR

If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.

The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.

It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.

Seeing contents of war file without extracting

The t option to the command line jar program will list the contents of a jar (or war) file, e.g.:

$ jar tf the-file.war


Related Topics



Leave a reply



Submit